ZedGraph - How to display a cursor at an x,y point without using the mouse?
I am drawing a curve in Zedgraph like this:
开发者_如何学GoGraphPane myPane = zgc.GraphPane;
PointPairList list1 = new PointPairList();
for(int i =0; i<10; i++)
list1.Add(i,i);
LineItem myCurve = myPane.AddCurve("Title",
list1, Color.Red, SymbolType.None);
zgc.AxisChange();
zgc.Refresh();
How can I display a cursor (or any other graphic object) at a certain x
, y
point on myCurve
like this:
SetCursor(myCurve, list1[3]);
Knowing specific point of your curve you can use GraphPane.GeneralTransform(...)
method
So using following code:
var myPoint = myCurve[3];
var screenPoint = myPane.GeneralTransform(myPoint.X, myPoint.Y, CoordType.AxisXYScale);
would give you coordinates transformed to specific point on screen (in pixels).
Then you need to find some higher-level method (probably in windows forms...) that would move your cursor to that point.
Here is a simple and more efficient example to create a cross cursor wich is part of the objects collection of the graph so you can operate zooming, printing on it. It add two "LineObj" in the "GraphObjList" collection. The code : Put a cursor at the 10th point of the first curve
Dim myPane As GraphPane = zg1.GraphPane
Dim myPoint As PointPair = myPane.CurveList.Item(0).Points(10)
Dim CurseurV1 As New LineObj(Color.Blue, myPoint.X,myPane.YAxis.Scale.Min, myPoint.X, myPane.YAxis.Scale.Max)
CurseurV1.Line.Width = 0.5
myPane.GraphObjList.Add(CurseurV1)
Dim CurseurH1 As New LineObj(Color.Blue, myPane.XAxis.Scale.Min,myPoint.Y, myPane.XAxis.Scale.Max, myPoint.Y)
CurseurH1.Line.Width = 1
myPane.GraphObjList.Add(CurseurH1)
It's done : you'd have a blue "cross" cursor on your graphe using ZedGraph.dll Version 5.1.2.878.
精彩评论