【问题标题】:Getting the x value of a point in a mschart获取 mschart 中某个点的 x 值
【发布时间】:2014-08-13 07:46:27
【问题描述】:

我有一个这样的极坐标图 当我点击图表中的一个点时,我需要显示该点的 x 值。我试过了;

  private void chart1_MouseClick(object sender, MouseEventArgs e)
    {
        double x=0; double y=0;
        var pos = e.Location;
        Point? clickPos = pos;

        var results = chart1.HitTest(pos.X, pos.Y, false, ChartElementType.PlottingArea);
            foreach(var result in results) {

                if(result.ChartElementType==ChartElementType.PlottingArea) {
                    x = result.ChartArea.AxisX.PixelPositionToValue(pos.X); ;
                    y=result.ChartArea.AxisY.PixelPositionToValue(pos.Y);

                }

                textBox1.Text=x.ToString();
                textBox2.Text=y.ToString();
            }


    }

但是这段代码给了我奇怪的坐标。例如,当我点击图表中的 (0,0) 点时,方位角为 179,增益为 5,00123。有人帮忙吗?

【问题讨论】:

  • 实际上,我已经找到了获取数据点值的方法。但是现在,我怎样才能得到点的值——而不是数据点,只是在图表中的某个地方,在轴之间——鼠标已经结束了?

标签: c# visual-studio-2010 mschart


【解决方案1】:

此代码可能会有所帮助:

private void chart_MouseDown(object sender, MouseEventArgs e)
{
    HitTestResult result = chart.HitTest(e.X, e.Y);
    if (result.ChartElementType == ChartElementType.DataPoint)
    {
        var selectedValue = chart.Series[0].Points[result.PointIndex].YValues[0];
        MessageBox.Show(selectedValue.ToString());
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多