I am using ZedGraph to draw my plots in C#. I need to know which bar (in bar chart) was clicked by a mouse. How can I do that? Is there any way to get a bar by a point and for example change bar`s color?
Use MouseClick
event and find the X and Y coordinates of the point where you clicked:
zg1.MouseClick+=new MouseEventHandler(zg1_MouseClick3);
private void zg1_MouseClick3(object sender, MouseEventArgs e)
{
PointF pt = (PointF)e.Location;
double x,y;
((ZedGraphControl)sender).MasterPane[0].ReverseTransform(pt, out x, out y);
// Do something with X and Y
}
Note, that I assumed we are operating on first pane (index 0) but if it is not your case, then you'll have to find which pane was clicked (see this example).
When you have X and Y position you should easily be able to guess which bar was clicked and do whatever you need with that information.
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