Hi,
I'm plotting 20 series of temperatures sampled once per second (all temperatures are sampled at exactly same time), visible interval will be 120 seconds. I change min and max value on x axis (min = DateTime.Now - 120 seconds, max = DateTime.Now) once per 100 ms to cause the graph sliding from right to left.
This is how I update the plot:
for (int i = 0; i < 20; i++) // iterate through series
{
var serie = model.SeriesData[i];
serie.Add(new ChartDataPoint(DateTime.Now, readings[i])); // append new temperature reading
for(int j = 0; j < serie.Count(); j++) { // delete old data
if ((DateTime)serie[j].XValue < model.Min) { // model.Min = DateTime.Now - 120 seconds
serie.Remove(serie[j]);
continue;
}
break;
}
}
This is how I update min and max value on x axis:
Xamarin.Forms.Device.StartTimer(TimeSpan.FromMilliseconds(100), () =>
{
min = DateTime.Now - TimeSpan.FromSeconds(60);
max = DateTime.Now;
NotifyPropertyChanged("Max"); // max and min values are binded
NotifyPropertyChanged("Min");
return true;
});
Can you please comment whether this is good way to update data and x axis of my real time plot? E.g. If every append/delete of sample causes chart to redraw, then my chart is redrawed at least 20 times in for loop, which is not ideal as it will be sufficient to redraw plot just once (after the for loop when all new samples were appended and old samples were deleted).