簡體   English   中英

從 OxyPlot ScatterPlot 獲取數據點

[英]Get Data Point from OxyPlot ScatterPlot

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

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

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM