How to find an index position on ZedGraph

Are there any ways to find the position of the curve index based on the current xPosition,

let's say I have an Item - MyCurve curve that has 20k points, and when the mouse moves, I could get the location of the mouse, and then I could get the x and y positions just using the following function.

double xPos=0, yPos=0; this.zedGraphControl1.GraphPane.ReverseTransform(MouseLoc, out xPos, out yPos); 

but I want to find data points from a curve element, any suggestions ...?

enter image description here Thanks in advance....:)

+4
source share
2 answers

Keep in mind that the following is only an approximation, it must be accurate, especially if you are approaching a point, but when you look at the position of the mouse, you cannot be directly at the point of your curve. It also assumes that your CurveItem Curve has points, and , which are evenly distributed.

 double startPos = Curve.Points[0].X double xStep = Curve.Points[Curve.NPts - 1].X / Curve.NPts; int xIndex = (int)(xPos / xStep + startPos); // Make sure it is in bounds xIndex = xIndex < 0 ? 0 : xIndex > Curve.NPts - 1 ? Curve.NPts - 1 : xIndex; 

OR you can use the following function:

 CurveItem n_curve; int index; zedGraphControl1.GraphPane.FindNearestPoint(mousePt, out n_curve, out index); 

But keep in mind that this will look for the nearest curve and the index of the nearest point inside that curve.

+3
source

If you do not programmatically use positions, but want to see the positions displayed on your chart, you can set zedGraphControl1.IsShowPointValues to true :

Display point values ​​in graph

+1
source

All Articles