5

I have a chart on a Windows Form with several line graphs. I would like to be able to get the x-coordinate from a mouse click on the chart in such a way that the user would be able to place vertical annotations on the chart at the location of the click. I looked at the Chart.HitTest function, but that will only do what I need if the user clicks on a data point, not anywhere in the chart area. Is there a way to do this easily?

Answers in C# or VB welcome.

Thanks!

bheklilr
  • 53,530
  • 6
  • 107
  • 163
  • http://stackoverflow.com/questions/9647666/finding-the-value-of-the-points-in-a-chart Did u check this ? – Quantbuff Mar 22 '12 at 18:23
  • I had not found that one, although I had searched a couple pages of stackoverflow before posting. That looks like exactly what I need. I'll post it as the answer, thanks! – bheklilr Mar 22 '12 at 19:14

1 Answers1

8

As @Quantbuff pointed out, this has been answered in this post.

Essentially, you must handle the click event (e) on the chart and call Chart.ChartAreas[0].AxisX.PixelPositionToValue(e.X) and Chart.ChartAreas[0].AxisY.PixelPositionToValue(e.Y) to get the values.

Community
  • 1
  • 1
bheklilr
  • 53,530
  • 6
  • 107
  • 163