0

I'm using classes from the C# Charting namespace to create a line graph, which is working fine so far. I have set a ToolTip so I can hover over a plot line and see its XY coordinates as follows:

chart_MPPTs.Series[seriesName].ToolTip = seriesName + " #VALX : #VALY{C}";

However, I got the " #VALX : #VALY{C}" portion from some sample code I found on the Web and I don't fully understand it. #VALX and #VALY appear to be macros or some other type of replacement mechanism and {C} is for formatting. However, I've been unable to find any documentation on these or the full set of such things that are available. Can anyone direct me to this information?

Also, the Microsoft documentation of the Charting classes and their contents seems even more terse than usual when it comes to examples or explanations of some of the terms used. Is there a book or any other resource that provides some good examples of using all of the various features of these classes?

TaW
  • 53,122
  • 8
  • 69
  • 111
BenevolentDeity
  • 693
  • 1
  • 4
  • 18
  • 1
    Check this out: https://msdn.microsoft.com/en-us/library/dd456687.aspx – Khale_Kitha Feb 15 '16 at 21:33
  • Did you get it from [#VALX value in MS Chart in C# isn't coming in “M/d H:mm” format](http://stackoverflow.com/q/20211242/719186)? – LarsTech Feb 15 '16 at 21:33
  • @Khale_Kitha - Yes, that's exactly what I was looking for. Thanks! – BenevolentDeity Feb 15 '16 at 21:47
  • @LarsTech - I did see the posting you are referring to but I actually got mine from a different one. However, I do have a related issue. My X axis represents the time of one day in 24-hour format but the values I used for it are expressed as type double, where the fractional parts are fractions of an hour. How would I format #VALX to display in HH:mm format? I tried #VALX{HH:mm} but all that displayed was the literal characters HH:mm, I assume because #VALX is not of the correct type. – BenevolentDeity Feb 15 '16 at 21:56
  • You really should try to add the data in the right type. __Or__ you could __add the tooltips right to each single point__ formatted from your source values. Not sure if that is possible if yours points are data-bound.. – TaW Feb 15 '16 at 22:50
  • @Taw - I believe the right type to allow the HH:mm format to work is DateTime isn't it? Is it possible to set up a graph so that the X-axis points accept data type DateTime? If so that's great. Of course I'll still need to label the X-axis grid with the integer values 0 through 24 for human usage. – BenevolentDeity Feb 16 '16 at 00:09
  • I'll post my previous comment as a separate posting since I think it's getting somewhat off topic. – BenevolentDeity Feb 16 '16 at 00:34
  • _Is it possible to set up a graph so that the X-axis points accept data type DateTime?_ Yes, this is very common: `chart1.Series[0].XValueType = ChartValueType.DateTime;` And if you do, the formatting you had should work just fine.. – TaW Feb 16 '16 at 00:40
  • @TaW - Great, and thanks! I tried that and it fixed the ToolTips right up the way I wanted. There's just one remaining issue (for now anyway). When I changed the XValueType to DateTime my 25 x-Axis labels also changed to DateTimes. I simply want them to be labeled 0 through 24. I've tried a few settings with ...AxisX.LabelStyle.Format but haven't found the right combination yet. – BenevolentDeity Feb 16 '16 at 01:27
  • Please see my answer! – TaW Feb 16 '16 at 03:06

1 Answers1

1

The # is part of the expression syntax for Chart Keywords. And yes, the part in curlies is about formatting, as explained at the bottom of the link..

Here are the settings you will need to make it work as mentioned iin the comments, i.e. display the label going from 0 - 24:

Make sure your x-value data are in fact added as DateTime and tell the chart about it:

chart_MPPTs.Series[seriesName].XValueType = ChartValueType.DateTime;

Now your tooltips should look right. Then to style the chart further try these settings:

chart_MPPTs.ChartAreas[0].AxisX.Interval = 1;
chart_MPPTs.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Hours;
chart_MPPTs.ChartAreas[0].AxisX.LabelStyle.Format = "hh"; 

Or "hh\\h"; or "h\\h"; for 00h - 24h or 0h - 24h..

All settings can also be done in the designer.

TaW
  • 53,122
  • 8
  • 69
  • 111
  • Thanks for all your help; I finally got it working. I believe your last 3 code statements should be ChartAreas, not Series, however. – BenevolentDeity Feb 16 '16 at 19:27