Search code examples
c#chartstooltip

What does '#' in a Chart ToolTip string mean?


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?


Solution

  • 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.