wpf OxyPlot 获得点击点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28001215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OxyPlot get clicked point
提问by Matt
I am trying to plot some circles on a scatter plot via:
我试图通过以下方式在散点图上绘制一些圆圈:
<Grid>
<oxy:PlotView x:Name="PlotView" Title="{Binding Title}" >
<oxy:PlotView.Axes>
<oxy:LinearAxis Position="Bottom" Minimum="-30" Maximum="30" IsAxisVisible="False" IsZoomEnabled="False" IsPanEnabled="False" />
<oxy:LinearAxis Position="Left" Minimum="0" Maximum="35" IsAxisVisible="False" IsZoomEnabled="False" IsPanEnabled="False"/>
</oxy:PlotView.Axes>
<oxy:PlotView.Series>
<oxy:ScatterSeries Height="100" Width="100" ItemsSource="{Binding Points}" MarkerType="Circle" />
</oxy:PlotView.Series>
</oxy:PlotView>
</Grid>
I cannot figure out how to enable some sort of click handler to have an event fired when a user clicks on a DataPoint.
我无法弄清楚如何启用某种单击处理程序以在用户单击DataPoint.
Examaple:
例子:
User clicks DataPointat (X, Y) = (0, 5), I would like to fire an event so I can handle the click of that point.
用户DataPoint在 (X, Y) = (0, 5) 处单击,我想触发一个事件,以便我可以处理该点的单击。
Is this possible with OxyPlot? I am currently investigating the Trackerto see if its possible that route, but starting to run out of ideas.
OxyPlot 可以做到这一点吗?我目前正在调查Tracker这条路线是否可行,但开始没有想法了。
回答by kennyzx
PlotViewhas defined mouse events, from which you can get the mouse coordinates, and InverseTransformis used to translate mouse coordinates to plot coordinates.
PlotView定义了鼠标事件,从中可以获得鼠标坐标,InverseTransform用于将鼠标坐标转换为绘图坐标。
Example:
例子:
var model = new PlotModel { Title = "Test Mouse Events" };
var s1 = new LineSeries();
model.Series.Add(s1);
double x;
s1.MouseDown += (s, e) =>
{
x = (s as LineSeries).InverseTransform(e.Position).X;
};
回答by Nora Powers
I couldn't get the accepted answer to work. The MouseDownhandler wouldn't receive events when the plot was left-clicked. It would, however, receive events for right-clicks and double-clicks.
我无法得到公认的工作答案。该MouseDown处理程序将不会收到事件时的阴谋左击。但是,它会接收右键单击和双击的事件。
My workaround is to listen for PreviewMouseDownon the PlotView.
我的解决方法是PreviewMouseDown在PlotView.

