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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With