Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knowing When a Particular Data-Point is Clicked?

Tags:

zedgraph

I have a bar graph and I want to allow the user to right click a particular bar, select some operation (add one or anything really) that will affect only that bar. Is this type of thing possible using ZedGraph?

like image 827
sooprise Avatar asked Feb 24 '23 12:02

sooprise


1 Answers

You can add a Mouse Click event to the Form and call FindNearestObject() passing in that mouse point, you'll get back the nearest object. Something like this perhaps:

private void zedGraphControl2_MouseClick(object sender, MouseEventArgs e)
{
    object nearestObject;
    int index;
    this.zedGraphControl2.GraphPane.FindNearestObject(new PointF(e.X, e.Y), this.CreateGraphics(), out nearestObject, out index);
    if (nearestObject != null && nearestObject.GetType() == typeof(BarItem))
    {
        BarItem barItem = (BarItem)nearestObject;
        barItem[index].Y += 1;
        zedGraphControl2.Invalidate();
    }
} 
like image 199
PeskyGnat Avatar answered May 16 '23 07:05

PeskyGnat