Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting x-coordinate on Chart from mouse click

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!

like image 863
bheklilr Avatar asked Mar 22 '12 15:03

bheklilr


1 Answers

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.

like image 184
bheklilr Avatar answered Sep 27 '22 19:09

bheklilr