We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Find nearest datapoint in series using touch point from chart area

Platform: UWP |
Control: SfChart |
Published Date: September 27, 2018 |
Last Revised Date: June 27, 2019

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

Chart area to find the nearest point in UWP

 

2X faster development

The ultimate UWP UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile