4

I'm trying to get the clicked position in my PlotView or PlotModel. But I just get some window-screen points not concerning any values in my PlotModel.

The question OxyPlot get clicked point is about clicking on LineSeries, not in any poisition of my plot.

Any ideas?

Eliahu Aaron
  • 4,103
  • 5
  • 27
  • 37
a.w.
  • 261
  • 2
  • 16

1 Answers1

8

Use InverseTransformation with your MouseEvent.Position and your axis.

private void MyPlotModel_MouseDown(object sender, OxyMouseDownEventArgs ex)
{
    OxyPlot.ElementCollection<OxyPlot.Axes.Axis> axisList = MyPlotModel.Axes;

    Axis xAxis = axisList.FirstOrDefault(ax => ax.Position == AxisPosition.Bottom);
    Axis yAxis = axisList.FirstOrDefault(ax => ax.Position == AxisPosition.Left);

    DataPoint dataPointp = OxyPlot.Axes.Axis.InverseTransform(ex.Position, xAxis, yAxis);

    // Do stuff with dataPointp ... 
}
Eliahu Aaron
  • 4,103
  • 5
  • 27
  • 37
a.w.
  • 261
  • 2
  • 16