场景
ZedGraph设置显示坐标值
zgc.IsShowCursorValues = true;
但是在刷新曲线图之后出现了鼠标焦点出现三个坐标值
解决方法是在其鼠标焦点悬浮事件中格式化其要显示的值,修改为举例最近的去曲线上的点。
注:
实现
//显示焦点值事件
zgc.CursorValueEvent += zgc_CursorValueEvent;
然后在方法中
private static string zgc_CursorValueEvent(ZedGraphControl sender, GraphPane pane, Point mousePt)
{
CurveItem nearstCurve;
int i;
Double x = 0.0;
Double y = 0.0;
Global.zedGraphControl1.GraphPane.FindNearestPoint(mousePt, out nearstCurve, out i);
if (nearstCurve!= null && nearstCurve.Points[i] != null && nearstCurve.Points[i].X != null)
{
x = nearstCurve.Points[i].X;
}
if (nearstCurve!= null && nearstCurve.Points[i] != null && nearstCurve.Points[i].Y != null)
{
y = nearstCurve.Points[i].Y;
}
return "X:" + x.ToString() + " Y:" + y.ToString();
}
效果