This is a migrated thread and some comments may be shown as answers.

Closest data point

7 Answers 91 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
David Renza
Top achievements
Rank 1
David Renza asked on 15 Oct 2013, 02:48 PM
Hello,

I'm using RadCartesianChart with multiple series (each series contains thousand of data points). I enabled ChartTrackBallBehavior (

<telerik:ChartTrackBallBehavior ShowIntersectionPoints="False" ShowTrackInfo="True" SnapMode="AllClosePoints" TrackInfoUpdated="ChartTrackBallBehavior_OnTrackInfoUpdated"/>) . Now in TrackInfoUpdated a would like find closest data point. Unfortunately property Context.ClosestDataPoint of TrackBallInfoEventArgs always returns first datapoint of first series regardless which datapoint is really closest. How can I detect really closest data point?

Thanks for help.

David

7 Answers, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 16 Oct 2013, 08:42 AM
Hello David,

I have attached a small project and snapshots to demonstrate that the ClosestPoint is not always the one from the first series.

However I think that this is is a slight misunderstanding - the chart considers a "closest point" the one that is horizontally closer to the mouse cursor. That is - for a horizontal line series it will calculate the X distance between the cursor and point and the Y distance.

If you need to calculate the point that is closest to the cursor with respect to both X and Y - you need to do this manually by calculating the distance between the e.Context.TouchLocation and all the data points that are shown in the track ball - Context.DataPointInfos[i].DataPoint.LayoutSlot.

Let us know if this helps or if you need further assistance.

Regards,
Petar Marchev
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Avneesh
Top achievements
Rank 1
answered on 16 Oct 2013, 11:53 AM
Hi Petar,
I tried using the Context.DataPointInfos[i].DataPoint.LayoutSlot but the layout slot has same value in all the datapoints in the context. How can i find the closest point then? I think DistanceToTouchLocation on datapointinfo is showing the difference and all the datapointinfo have the same value. i wanted to find out the series which is closest to the mouse cursor.

Thanks
Avneesh


0
David Renza
Top achievements
Rank 1
answered on 16 Oct 2013, 01:35 PM
Hi Petar,

Context.DataPointInfos[i].DataPoint.LayoutSlot was exactly what I needed, I don't understand how could i miss it. Thank you for pointing on that.
But I have another question. When moving with mouse cursor up and down and category is not changing then the event TrackInfoUpdated is not fired at all. This is intended behavior or bug?

Avneesh: As I understand DistanceToTouchLocation  is calculated for X axis so all Context.DataPointInfos have same value. If you need closest datapoint on Y axis, try something like that:

DataPointInfo closestDataPoint = e.Context.DataPointInfos.OrderBy(x => Math.Abs(e.Context.TouchLocation.Y - x.DataPoint.LayoutSlot.Y)).FirstOrDefault();



David
0
Avneesh
Top achievements
Rank 1
answered on 16 Oct 2013, 02:01 PM
Thanks David, managed to get it using the Y Axis.
0
Avneesh
Top achievements
Rank 1
answered on 30 Oct 2013, 04:32 PM
Hi Petar/David,
I am finding the closest series whenever the TrackInfoUpdated  event is fired - which works fine but when the tracker line is displayed and the user moves mouse up/down on tracker line, the event is not fired and I am not able to then determine what closest series exists near the mouse. I even tried trackballControl.updateLayout() when the mouse moves ( added onmousemove in chart)  but no luck. Is there any way to capture the TrackBallInfoEventArgs.Context which i can then use to determine what series are closest?


Thanks 
Avneesh
0
Petar Marchev
Telerik team
answered on 31 Oct 2013, 12:44 PM
Hello,

The event is not raised because the data points are the same. This is not a bug in the control and is actually by design. There is no way to change this behavior and to force the event to be raised or to get the new Context (because such new Context does not exist).

Perhaps you need to give up the built-in track ball behavior and implement the functionality that you need manually. I have attached a simple project which demonstrates one way you can do this manually. You can apply whatever logic you need in the MouseMove event.

Regards,
Petar Marchev
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Avneesh
Top achievements
Rank 1
answered on 31 Oct 2013, 01:03 PM
Thanks for the great help Petar, going to try it now. 
Tags
ChartView
Asked by
David Renza
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Avneesh
Top achievements
Rank 1
David Renza
Top achievements
Rank 1
Share this question
or