从OxyPlot ScatterPlot获取数据点

时间:2015-10-17 01:31:17

标签: c# winforms oxyplot

我想知道如何(具体地)获取我使用OxyPlot绘制的散点图的x坐标。

//user clicks on graph line data...
//x-coordinate gets assigned to variable
int x = ...

我使用winforms。

编辑:

   private void plotView_Click(object sender, EventArgs e){
        plotView.ActualModel.Series[0].MouseDown += (s, e0) =>
        {
            if (e0.ChangedButton != OxyMouseButton.Left)
                return;
            else
                pointx = (int)e0.HitTestResult.NearestHitPoint.X;
        };
    }

工作代码:

        s0.MouseDown += (s, e0) =>
        {
            if (e0.ChangedButton == OxyMouseButton.Left)
            {
                var item = e0.HitTestResult.Item as ScatterPoint;
                if (item != null)
                {
                    pointx = (int)item.X;
                }
            }
        };

1 个答案:

答案 0 :(得分:1)

您可以附加系列的鼠标按下事件,如下所示:

var model = new PlotModel { Title = "Test Mouse Events" };

var s1 = new LineSeries();
model.Series.Add(s1);

double x;

s1.MouseDown += (s, e) =>
            {
                x = e.Position.X;
            };

改编自此处的示例代码:https://github.com/oxyplot/oxyplot/blob/09fc7c50e080f702315a51af57a70d7a47024040/Source/Examples/ExampleLibrary/Examples/MouseEventExamples.cs

并在此处演示:http://resources.oxyplot.org/examplebrowser/ =>向下滚动到鼠标事件

编辑:我发现你从x得到的位置是你必须转换的屏幕坐标才能找到正确的轴点,如下所示:

x = (s as LineSeries).InverseTransform(e0.Position).X;