Search code examples
c#mschart

Tooltip displaying wrong datetime


I have a mschart control where I am graphing some points from a datagrid. After populating my chart I do the following code:

foreach (Series s in chart1.Series)
{
    s.ToolTip = "X=#VALX, Y=#VALY";
}

This does set the tooltip, but as shown in the screen shot below, when I mouse over the point it has the wrong x value. Which is weird because the x-axis has the correct values so if you line the interval up with the point you can tell what it is, but for some reason the tooltip is wrong (but the y-value in the tooltip is correct).

MsChart

Any help is appreciated.

Edit: I asked this question 6 years ago and now I know a little more about MSCharts. A couple of things that will cause this;

  1. Storing your data as a String instead of a DateTime format can cause the tooltip to not work properly. (which is what happened here, all my timestamps were being stored as strings. Don't do this, it's much better to use a Datetime).
  2. Make sure your ChartType is type Line chart and not FastLine chart. Tool tips won't work with FastLines.

Solution

  • In my code I had the following:

            foreach (Series s in chart1.Series)
            {
                s.IsXValueIndexed = false;
                s.XValueType = ChartValueType.DateTime;
            }
    

    I removed the s.XValueType from my code and the tooltip started working properly.