简体   繁体   English

OxyPlot 获得点击点

[英]OxyPlot get clicked point

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 DataPoint at (X, Y) = (0, 5), I would like to fire an event so I can handle the click of that point.用户在 (X, Y) = (0, 5) 处单击DataPoint ,我想触发一个事件,以便我可以处理该点的单击。

Is this possible with OxyPlot? OxyPlot 可以做到这一点吗? I am currently investigating the Tracker to see if its possible that route, but starting to run out of ideas.我目前正在调查Tracker ,看看它是否有可能走这条路线,但开始没有想法了。

PlotView has defined mouse events, from which you can get the mouse coordinates, and InverseTransform is 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;
};

I couldn't get the accepted answer to work.我无法得到公认的工作答案。 The MouseDown handler wouldn't receive events when the plot was left-clicked. MouseDown左键单击绘图时, MouseDown处理程序不会接收事件。 It would, however, receive events for right-clicks and double-clicks.但是,它会接收右键单击和双击的事件。

My workaround is to listen for PreviewMouseDown on the PlotView .我的解决方法是在PlotView上监听PreviewMouseDown

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM