Check if point was selected

May 6, 2012 at 2:17 PM

Hello,

I would like to ask how can I check if point from series was selected?Is it possible to somehow check if default point mousehover event was invoked?

I am newbie in using oxyplot library :)

Coordinator
May 7, 2012 at 5:05 PM

The mouse events that was just added contains a "HitTestResult" in the event arguments.

The hit test results contains a property "Index" which should give you the index of the point that was clicked on. Note that the index is of type double; if the index = 4.5 it means that the user clicked on the line half-way between point 4 and 5 (in the case of a LineSeries). You have to decide if it is close enough, and then use Math.Round(Index) to get the index of the nearest point. 

Note that selection is not completely implemented yet.

Oct 12, 2012 at 9:35 AM

I know my reply is a bit late, but here is a code fragment for anyone to use:

 

// Subscribe to the event
plot.Model.MouseDown += new EventHandler<OxyPlot.OxyMouseEventArgs>(plotModel_MouseDown);


// event handler
void plotModel_MouseDown(object sender, OxyPlot.OxyMouseEventArgs e)       
{
   Plot plot = sender as Plot;
   switch (e.ChangedButton)
   {
      case OxyPlot.OxyMouseButton.Left:
         OxyPlot.Series series = plot.GetSeriesFromPoint(e.Position, 10);
         if (series != null)
         {
            OxyPlot.TrackerHitResult result = series.GetNearestPoint(e.Position, true);
            if (result != null && result.DataPoint != null)
            {
               // data point nearest to the click
               OxyPlot.IDataPoint dataPoint = result.DataPoint;

            }
        }
        break;
   }
}