Category / Section
Find nearest datapoint in series using touch point from chart area
1 min read
You can get the nearest data point in series from wherever you touch the chart area using the PointerMoved event in chart and using the FindNearestChartPoint method in ChartSeries.
Please refer to the following code sample to get the nearest data point in series.
C#
private void Chart_PointerMoved(object sender, PointerRoutedEventArgs e)
{
FieldInfo feild = typeof(ChartBase).GetField("AdorningCanvas", BindingFlags.NonPublic | BindingFlags.Instance);
UIElement canvas = feild.GetValue(Chart) as UIElement;
var pointer = e.GetCurrentPoint(canvas);
double xvalue = pointer.Position.X;
double yvalue = pointer.Position.Y;
double stackvalue = double.NaN;
Point point = new Point(xvalue, yvalue);
Chart.Series[0].FindNearestChartPoint(point, out xvalue, out yvalue, out stackvalue);
textblock.Text = "Nearest X Point is " + xvalue.ToString();
textblock1.Text = "Nearest Y Point is " + yvalue.ToString();
}
Output
Did not find the solution
Contact Support