Hi Thomas,
I also found that running the timer event on the UI thread updates the charts much better when
ZoomStyles.FullChart or
ZoomStyles.Classic, for example:
Code: Select all
int count = 1;
public LinearGauge[] _gauges;
int _counter = 0;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
var scroll = FindViewById<ScrollView> (Resource.Id.scroll);
var scrollRoot = FindViewById<LinearLayout> (Resource.Id.scrollRoot);
var length = 15;
_gauges = new LinearGauge[length];
for (int i = 0; i < length; i++) {
TChart chart = new TChart (this);
chart.Aspect.View3D = false;
var gauge = new LinearGauge (chart.Chart);
_gauges [i] = gauge;
gauge.Value = 10;
chart.Zoom.Style = ZoomStyles.FullChart;
chart.LayoutParameters = new LinearLayout.LayoutParams (300, 150);
scrollRoot.AddView (chart);
}
var timer = new System.Timers.Timer (1000);
timer.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => {
foreach (var gauge in _gauges) {
RunOnUiThread(delegate
{
gauge.Chart.AutoRepaint = false;
gauge.Value = _counter++;
gauge.Chart.AutoRepaint = true;
gauge.Chart.Invalidate();
});
}
};
timer.Start ();
}
The scrolling issue is most likely related to what's explained
here. ScrollView requires child controls to redraw, since charts are already being redrawn to update values probably they are forced to be redrawn before the previous draw cycle has completed and hence the poor scrolling experience. Looks like this behaviour is present in those situations where refreshing rate is faster (
ZoomStyles.None and
ZoomStyles.FullChart with
RunOnUiThread). Other combinations don't show this problem because they just refresh too slow and you don't see
LinearGauge value increasing. This problem is what we tried to address with the RealTimeCharting demo and
ZoomStyles.None implementation, which internally uses a
SurfaceView. That example uses a
FastLine series, this specific series and the complete demo are optimized for performance (no grid lines, manual axes scale, no legend, no gradients, etc.). Therefore, your example performance might be improved simplifying some elements in your gauges: axes and gradients, for example. I'll give it a go and get back to you if I can improve that.