OxyPlot get clicked point

别来无恙 提交于 2019-12-06 06:39:33

问题


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 can not figure out how to enable some sort of click handler to have an event fired when a user clicks on a DataPoint.

Exmaple:

User clicks datapoint at X: 0, Y: 5, I would like to fire an event so I can handle the click of that point.

Is this possible with OxyPlot? I am currently investigating the Tracker to see if its possible that route, but starting to run out of ideas.


回答1:


PlotView has defined Mouse events, from which you can get the mouse coordinates. And InverseTransform is used to translate mouse coordinates to plot coordinates.

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;
    };



回答2:


I couldn't get the accepted answer to work. The MouseDown handler wouldn't receive events when the plot was left-clicked. It would, however, receive events for right-clicks and double-clicks.

My workaround is to listen for PreviewMouseDown on the PlotView.



来源:https://stackoverflow.com/questions/28001215/oxyplot-get-clicked-point

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!