BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
How to clear the chart when there's no data?
By clear, I mean the axises still exist, but previous curves cleared.
Hi Zhu,
You can achieve your requirement with the help of setting the isVisible property in the axes to false when there is no data available in the chart. We have shared the related UG documentation below for your reference.
UG, https://help.syncfusion.com/flutter/cartesian-charts/axis-customization#axis-visibility
If you have any further query please get back to use.
Regards,
Yuvaraj.
Hi, Yuvaraj,
I mean to clear the data traces, but keep axises on.
Regards,
Zhu.
Hi, Yuvaraj,
I got it, clearing the datasouces should be the way to go.
Regards,
Zhu.
...
Hi, Yuvaraj,
I tried to clear the datasources, but doing that would bring errors..
Is it possible to add a clear method to SfCartesianChart class?
Regards,
Zhu.
Hi Zhu,
If you want to clear the series in the chart you can achieve this with the help of the updateDataSource method. Here you need to clear the chartData list which holds the data source then generated a list on index value based on the chartData length before it was cleared and set it to the removedDataIndexes property. Then the particular series will be removed from the chart. Likewise, you can remove all the series in the chart. We have shared the code snippet below for your reference.
Code snippet:
floatingActionButton: ElevatedButton( onPressed: () { int length = chartData.length; chartData = []; _seriesController.updateDataSource( removedDataIndexes: List.generate(length, (index) => index).toList()); }, child: Text('Clear'), ), |
Regards,
Yuvaraj.
Hi, Yuvaraj,
It works, thank you so much for the help.
Best Regards,
Zhu.
Most Welcome. Kindly get back to us if you have further queries. We are always happy to assist you.