gpt4 book ai didi

c# - 从 OxyPlot 散点图中获取数据点

转载 作者:太空宇宙 更新时间:2023-11-03 12:58:15 28 4
gpt4 key购买 nike

我想知道如何(具体而言)获得我使用 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;

关于c# - 从 OxyPlot 散点图中获取数据点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33181794/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com