chart refresh rate

1 Answer 126 Views
Chart Chart - Xamarin.Android
Davide
Top achievements
Rank 1
Iron
Davide asked on 04 Nov 2021, 09:10 AM

Hello everyone,

I have a question on 'refreshing' chart when data source in updated.

Briefly: is there a fixed refresh rate for RadCartesianChart ?

In deep: in my xamarin forms app I added a RadCartesianChart  with a LineSerie updated as follow

     <telerikChart:LineSeries
                        CategoryBinding="MillisecondsCategory"
                        ItemsSource="{Binding Measures}"
                        Stroke="{StaticResource AccentColor}"
                        ValueBinding="Value" />

The "Measures" are data that I received in real time, therefore  they are constantly updated

 private IList<SensorMeasure> measures;
        public IList<SensorMeasure> Measures
        {
            get => measures;
            set => Set(ref measures, value);
        }

I have two way to add data to "Measures": 1) 100 samples every second 2) one sample every 10 millisecond.
When I add data in the way number one everything seems ok and I see the chart updating itself every second with a 'block' of new data, but if I try the second approach (in order to have a "real" real-time visualization) the chart seems to refresh itself in the same way as first one... that's why I am asking:

are there limits in the refresh rate of RadCartesianChart ? Is there a property that I can set to 'speed up' the refreshing process?

I tested my app only on Android device since I am not able to test on iOs.

Thanks in advance

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 04 Nov 2021, 08:42 PM

Hi Davide,

Thank you for sharing the code. I have two recommendations for you to get the desired result:

1) Do not use an IList for anything you bind to the UI that you expect to change, instead use an ObservableCollection.

public ObservableCollection<SensorMeasure> Measures

 

2) Add new items to the collection as they come in. Then remove the oldest item. This will give the appearance of a realtime time because all the data points are flowing into the chart form the right and leaving out of the left.

private void AddNewItemToSeries(SensorMeasure item)
{
    var maxItemsInSeries = 30;

    // This is IMPORTANT! If you do not remove older items, your app will eventually slow down, run out of memory and crash.
    if(Measures.Count > maxItemsInSeries)
        Measures.RemoveAt(0); // remove the oldest item

    // Add the new item, an ObservableCollection will automatically update the UI
    Measures.Add(item);
}

 

Other Recommendation

> Warning, a data point every 10 miliseconds is pretty high because it's faster than the UI's databinding can react to, but also you will fill up the series with too many data points to make the view even reasonable to watch. I would strongly recommend not plotting every single point and instead sample those incoming datapoints (maybe do one every 10, this will still get you 10 updates a second and not bog down your app's memory usage).

Regards,
Lance | Manager Technical Support
Progress Telerik

Remote troubleshooting is now easier with Telerik Fiddler Jam. Get the full context to end-users' issues in just three steps! Start your trial here - https://www.telerik.com/fiddler-jam.
Tags
Chart Chart - Xamarin.Android
Asked by
Davide
Top achievements
Rank 1
Iron
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or