从OxyPlot ScatterPlot获取数据点
本文关键字:数据 获取 ScatterPlot OxyPlot | 更新日期: 2023-09-27 18:18:01
我想知道如何(具体地)获得我使用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;