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

How to get a datapoint on mouse click

[SF version is 13.1]
I have a Fast Line Series in a chart with a category axis as Xaxis populated with Datetime values mapped to a Numerical axis as Yaxis. 
When I click on the chart , I want to get the corresponding DateTime,Numeric (X,Y) values..?

How can this be done..?

Thanks. 

5 Replies

SS Suresh S Syncfusion Team June 11, 2015 01:04 PM UTC

Hi Senthil,

Thanks for update.

We have analyzed your query and achieved your requirement for getting point info as shown in the below code snippet. Also, we have prepared a sample based on this, please download from below location,

CodeSnippet:

var chart = sender as SfChart;

FrameworkElement element = e.OriginalSource as FrameworkElement;

 

            if (element != null && element.Tag is ChartSegment)

            {

                FastLineSegment segment = element.Tag as FastLineSegment;

                var series = segment.Series as FastLineSeries;

                double x, y, stackedValue;

 

                segment.Series.FindNearestChartPoint((Point)e.GetPosition(sfchart), out x, out y, out stackedValue);

 

                MessageBox.Show("X:" + x);

           }

Sample: TrackBallBehavior

Please let us know in case of any query.

Regards,

Suresh S



SR Senthil Ramanathan June 17, 2015 05:21 AM UTC

Not sure it's working correctly. I modified the sample slightly to show the dates on click and the very first point in the series I am able to click seems to off by a few days. 

Could you please check..?
private void sfchart_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var chart = sender as SfChart;
            FrameworkElement element = e.OriginalSource as FrameworkElement;
 
            if (element != null && element.Tag is ChartSegment)
            {
                FastLineSegment segment = element.Tag as FastLineSegment;
                var series = segment.Series as FastLineSeries;
                double x, y, stackedValue;
 
                segment.Series.FindNearestChartPoint((Point)e.GetPosition(sfchart), out x, out y, out stackedValue);
 
                //MessageBox.Show("X:" + x);
 
                var items = segment.Item as List<object>;
                if (items != null && items.First() is Model && items.Count > x)
                {
                    var key = ((Model)items[(int)x]).Year;
                    MessageBox.Show(key + ":" + y + ":" + stackedValue);
                }
           }
        }


SS Suresh S Syncfusion Team June 17, 2015 01:10 PM UTC

Hi Senthil,

Thanks for update.

We have analyzed your query and achieved your requirement for getting data point as shown in below code snippet. Also, we have modified the sample based on this, please download from below location.

Code Snippet:

private void sfchart_MouseDown(object sender, MouseButtonEventArgs e)

        {

            var chart = sender as SfChart;

            FrameworkElement element = e.OriginalSource as FrameworkElement;

 

            if (element != null && element.Tag is ChartSegment)

            {

                FastLineSegment segment = element.Tag as FastLineSegment;

                var series = segment.Series as FastLineSeries;

                double x, y, stackedValue;

                segment.Series.FindNearestChartPoint((Point)e.GetPosition(sfchart), out x, out y, out stackedValue);

                Point dataPoint = e.GetPosition(sfchart);

                var data = series.GetDataPointIndex(dataPoint.X, dataPoint.Y);

               

                if (data == -1) return;

 

                var items = segment.Item as List<object>;

                if (items != null && items.First() is Model && items.Count > data)

                {

                    var key = ((Model)items[(int)data]).Year;

                    var valueY = ((Model)items[(int)data]).India;

                    MessageBox.Show(key + ":" + valueY + ":" + stackedValue);

                }

           }

        }

Sample: TrackBallBehavior

Please let us know in case of any query.

Regards,

Suresh S



SR Senthil Ramanathan June 18, 2015 03:24 AM UTC

That solved the offset problem. Thanks. 


SS Suresh S Syncfusion Team June 18, 2015 10:26 AM UTC

Hi Senthil,

Thanks for update.
We are glad to know the issue is resolved.
Please let us know in case of any query.

Regards.
Suresh S

Loader.
Live Chat Icon For mobile
Up arrow icon