I am trying to have a Chart updated dynamically with the SfCartesianChart component.
I tried to follow the different documentation and used the following initialization.
chart = new SfCartesianChart();
dataBinding = new SensorDataViewModel();
chart.BindingContext = dataBinding;
var binding = new Binding() { Path = "Data" };
LineSeries series = new LineSeries() { ... };
series.SetBinding(LineSeries.ItemsSourceProperty, binding);
chart.Series.Add(series);
with this code, the initial series is displayed but if I add any data on runtime with
dataBinding.Data.Add(data);
I get the following error:
Windows:
An exception of type 'System.Runtime.InteropServices.COMException' occurred in WinRT.Runtime.dll but was not handled in user code
The application called an interface that was marshalled for a different thread. (0x8001010E (RPC_E_WRONG_THREAD))
Android:
[ERROR] FATAL UNHANDLED EXCEPTION: Android.Util.AndroidRuntimeException: Animators may only be run on Looper threads
After trying several things, I found that if I set
series.EnableAnimation = true;
after the line series.SetBinding(LineSeries.ItemsSourceProperty, binding);
the dynamic data is displayed on Windows.
but I still have the same error on Android.
[ERROR] FATAL UNHANDLED EXCEPTION: Android.Util.AndroidRuntimeException: Animators may only be run on Looper threads
Is there a way to display data changed on runtime at the moment on all platforms?
Hi Oliver,
We are currently validating this, and we will update you with complete details on or before 19th May, 2022.
Regards,
Yuvaraj.
Hi Oliver,
We have checked the reported problem "Dynamic data update
with EnableAnimation, SfCartesianChart throws exception" and it was not
able to reproduce it at our end. And we would like to suggest that use Dispatcher
it may resolved, due to different threads sync in the UI while update the
datapoint.
We have attached the Maui chart sample with a dynamic data update for your reference. Please find the sample in the below attachment.
If you are still experiencing issues, could you please send us a modified sample with the issue reproduced state which will be helpful to provide a better solution as soon as possible?
Regards,
Yuvaraj.
Thank you for your information and the sample code.
I found out the problem in my code.
The data was updated through a call from a background thread (listener), so when inserting the data to the Series, as you noted in your comment, I had to use the Dispatcher. Once adapting my code with the Dispatcher the data update and display worked perfectly.
Thank you again for you
Hi Oliver,
Thanks for your update.
Please let us know if you have any further assistance.
Regards,
Yuvaraj.