How to find the index position on ZedGraph

允我心安 提交于 2019-12-12 12:08:50

问题


Is there any ways around to find the index position of a curve, based on the current xPosition,

let's say I have a curve Item - MyCurve, which has 20k points and when the mouse moves I could get the mouse location & then I could get the x & y positions by simply using the following function.

double xPos=0, yPos=0;

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

but I want to find the data points from the curve item, any suggestions...?

Thanks in advance....:)

回答1:


Bear in mind that the following is only an approximation, it should be accurate especially when you the mouse gets closer to the point, but as you are looking at the mouse position you may not be directly on a point on your curve. It also assumes that your CurveItem Curve has points, and that they 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 that will look for the nearest curve and the index of the nearest point within that curve.




回答2:


If you are not concerned with using the positions programmatically, but only want to see the positions displayed in your graph, you can set zedGraphControl1.IsShowPointValues to true:



来源:https://stackoverflow.com/questions/11779274/how-to-find-the-index-position-on-zedgraph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!