显示鼠标轴坐标上的图表控件 [英] Showing Mouse Axis Coordinates on Chart Control

查看:415
本文介绍了显示鼠标轴坐标上的图表控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单的方法来获取X / Y在图表区域中的任何点的坐标(相对于该图表当然轴)?



截至目前我好不容易才找回坐标当鼠标在一个系列(不外)

 私人无效chart_GetToolTipText(对象发件人,ToolTipEventArgs E)
{
如果(e.HitTestResult.Series!= NULL)
{
e.Text = e.HitTestResult.Series.Points [e.HitTestResult.PointIndex。 YValues​​ [0] +\\\
+ DateTime.FromOADate(e.HitTestResult.Series.Points [e.HitTestResult.PointIndex] .XValue);
}
}


解决方案

不管怎样一如既往以MS图表控件,有没有简单的方法做事情,结果却得到完成一个时髦的解决办法的事情。我伤心地习惯了...

 私人无效chart1_MouseWhatever(对象发件人,MouseEventArgs E)
$ { b $ b chartArea1.CursorX.SetCursorPixelPosition(新点(例如,EY),TRUE);
chartArea1.CursorY.SetCursorPixelPosition(新点(e.X,e.Y),TRUE);

双的pX = chartArea1.CursorX.Position; // X坐标坐标鼠标光标
双PY = chartArea1.CursorY.Position的; // Y轴坐标鼠标光标
}


Is there a simple way to retrieve the X/Y coordinates of ANY point in the chart Area (relative to that chart Axis of course)?

As of now, I just managed to retrieve coordinates when the mouse is on a Series (not outside)

private void chart_GetToolTipText(object sender, ToolTipEventArgs e)
{
    if (e.HitTestResult.Series != null)
    {
        e.Text = e.HitTestResult.Series.Points[e.HitTestResult.PointIndex].YValues[0] + " \n " + DateTime.FromOADate(e.HitTestResult.Series.Points[e.HitTestResult.PointIndex].XValue);
    }
}

解决方案

Anyway, as always with MS Chart Controls, there is no easy way to do things,
but a funky workaround to get things done. I am sadly getting used to it...

private void chart1_MouseWhatever(object sender, MouseEventArgs e)
{
    chartArea1.CursorX.SetCursorPixelPosition(new Point(e.X, e.Y), true);
    chartArea1.CursorY.SetCursorPixelPosition(new Point(e.X, e.Y), true);

    double pX = chartArea1.CursorX.Position; //X Axis Coordinate of your mouse cursor
    double pY = chartArea1.CursorY.Position; //Y Axis Coordinate of your mouse cursor
}

这篇关于显示鼠标轴坐标上的图表控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆