Check if point was selected

Oystein Bjorke 10 jaar geleden 0
This discussion was imported from CodePlex

Xgamer wrote at 2012-05-06 15:17:

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 :)


objo wrote at 2012-05-07 18:05:

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.


viklele wrote at 2012-10-12 10:35:

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