Closest data point

8 posts, 0 answers
  1. David Renza
    David Renza avatar
    13 posts
    Member since:
    May 2010

    Posted 15 Oct 2013 Link to this post

    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

  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 16 Oct 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Avneesh
    Avneesh avatar
    13 posts
    Member since:
    Jul 2013

    Posted 16 Oct 2013 Link to this post

    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


  5. David Renza
    David Renza avatar
    13 posts
    Member since:
    May 2010

    Posted 16 Oct 2013 Link to this post

    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
  6. Avneesh
    Avneesh avatar
    13 posts
    Member since:
    Jul 2013

    Posted 16 Oct 2013 Link to this post

    Thanks David, managed to get it using the Y Axis.
  7. Avneesh
    Avneesh avatar
    13 posts
    Member since:
    Jul 2013

    Posted 30 Oct 2013 Link to this post

    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
  8. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 31 Oct 2013 Link to this post

    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 >>
  9. Avneesh
    Avneesh avatar
    13 posts
    Member since:
    Jul 2013

    Posted 31 Oct 2013 Link to this post

    Thanks for the great help Petar, going to try it now. 
Back to Top
UI for WPF is Visual Studio 2017 Ready