2
votes

I am using mschart in C#4.0 to generate line chart and I am createing DataPoint to show the tooltip on points but the probelm is, tool tip is coming on each point of line however, I want only on my datapoint.

1
Yes I am facing same problem. Can anybody help us?user1241779

1 Answers

2
votes

You may have found a solution to your question, as this post is quite old. But I wanted to do the same thing, so here is how I did:

First, when I add a data point to a Serie, I do not set the ToolTip property of the data point. Then, I use the code:

public void Form1()
{
   //Add a handler for the GetToolTipText event
   chart1.GetToolTipText += new EventHandler<ToolTipEventArgs>(chart1_GetToolTipText);
}

private void chart1_GetToolTipText(object sender, ToolTipEventArgs e)
{
   //Check selected chart element is a data point and set tooltip text
   if (e.HitTestResult.ChartElementType == ChartElementType.DataPoint)
   {   
      //Get selected data point
      DataPoint dataPoint = (DataPoint)e.HitTestResult.Object;

      //Is it my datapoint?
      if (dataPoint == myDataPoint)
      {
         //Yes, set text
         e.Text = "My data point value " + dataPoint.XValue.ToString() + dataPoint.YValues[0].ToString();
      }
      else
      {
         //No, void string
         e.Text = "";
      }
   }
}