【问题标题】:Get Data Point from OxyPlot ScatterPlot从 OxyPlot ScatterPlot 获取数据点
【发布时间】:2015-10-21 04:20:28
【问题描述】:

我想知道如何(特别是)获得我使用 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;
                }
            }
        };

【问题讨论】:

    标签: c# winforms oxyplot


    【解决方案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;
    

    【讨论】:

    • 我需要在鼠标单击事件中执行此操作,但当我这样做时,我收到一个错误提示 'e' cannot be declared in this scope,因此我将其重命名为 e0。当我这样做时,我总是得到 x 的零。我该如何解决这个问题?
    • 也许可以尝试将 int x 设为双精度值,这样它就不会将任何双精度值截断为 0。除此之外,您可以编辑您的代码,我可以查看您在做什么。
    • 哦,如果您正在寻找点击的实际坐标(不是我可能假设的点),请执行以下操作:“e0.Position.X”
    • 是的,我正在寻找单击的散点图(图形)的精确坐标。你是什​​么意思,做:-?
    • 我尝试将 int x 设为 double 和 int。它显示了两者的值,但它们与实际值相差甚远。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-26
    • 2015-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    相关资源
    最近更新 更多