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

Calculate closest previous point in chart

5 Answers 75 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Stefano
Top achievements
Rank 1
Iron
Stefano asked on 21 Apr 2021, 11:10 AM

Hi,

I have a step line chart with the trackball enabled. The ChartTrackBallBehavior is like this.

<telerik:ChartTrackBallBehavior ShowIntersectionPoints="True" ShowTrackInfo="True" SnapMode="None" SnapSinglePointPerSeries="True"/>

 

My problem is that the closest point can be on the left or on the right of the trackball line. I need the closest point to be always the one on the left. Is there a way to change the default behavior so that I can programmatically set the closest point when trackball line moves? I have attached an image to better explain my problem.

 

 

5 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 26 Apr 2021, 09:03 AM

Hello Stefano, 

Thank you for the provided image.

Generally speaking, I am not sure when you want to show the right point. You can control the points inside the TrackBall by subscribing to the TrackInfoUpdated event of the ChartTrackBallBehavior. The event arguments expose a ChartDataContext property. This object holds the closest data point and a DataPointInfos collection. You can clear this collection and populate it with points that you want to show in the trackball.

Regards,
Dinko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Stefano
Top achievements
Rank 1
Iron
answered on 07 May 2021, 07:56 PM

Hello Dinko,

thank for your answer. I tried to investigate the approach you suggested, but there are a couple of limitations.

The first one is that I can't find a way to create DataPointInfo since constructor is internal only. Is there a point where all DataPointInfo for the chart are stored so that I can use them?.

The second problem is that the event isn't triggered when the trackball passes a point where a value changes, but only when it passes in the middle between two values.

I then tried to investigate Position_Changing event but it seemes a dead end.

Generally speaking, in the trackball I would like to show the current value and not the future one even if it's the closest. This is why I need the left value.

Any thought?

0
Dinko | Tech Support Engineer
Telerik team
answered on 10 May 2021, 08:16 AM

Hello Stefano,

You are right that you can't create a DataPointInfo object. I have overlooked that and I apologize. After checking the source code, the required behavior can't be achieved with the default TrackBall of the RadChartView. After passing the middle distance of two points, the trackball will show the next one. We will consider adding a note in the article to mentioned the above behavior.

What I can suggest here is to create a custom trackball. You can use ChartView Annotation to achieve a similar effect. There is an SDK example in our GitHub repository which demonstrates this. You can check it out and let me know if further questions arise.

Regards,
Dinko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

1
Stefano
Top achievements
Rank 1
Iron
answered on 13 May 2021, 07:44 PM

Hello Dinko,

in the end I solved the problem using another approach that was approved by customer. I disabled the trackball, and left only the trackline visible. In the PositionChanging event I use the ConvertPointToData method of the RadCartesianChart instance to get the time at cursor position. I then use this time to search the previous item in datasource of the line. I then use the value of that item and show it outside the chart. close to the legend. It's not the best solution, but it works.

 

For the future, can I suggest you to consider marking the FindClosestPoint method as public and virtual? This way developers can customize the way they find the closest point.

 

Regards,

Stefano

0
Dinko | Tech Support Engineer
Telerik team
answered on 14 May 2021, 01:16 PM

Hello Stefano,

I am happy to hear that you have found a solution for your case. You are right that such improvement will get in handy for scenarios like yours. This possible functionality is logged as a feature request in our Feedback Portal. You can vote for its implementation to increase its priority.

Regards,
Dinko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products, quickly just got a fresh new look + new and improved content, including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ChartView
Asked by
Stefano
Top achievements
Rank 1
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Stefano
Top achievements
Rank 1
Iron
Share this question
or