We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to clear the chart when there's no data?

How to clear the chart when there's no data?

By clear, I mean the axises still exist, but previous curves cleared.


7 Replies 1 reply marked as answer

YG Yuvaraj Gajaraj Syncfusion Team March 27, 2023 12:14 PM UTC

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.



ZH Zhu March 28, 2023 01:29 AM UTC

Hi, Yuvaraj,


I mean to clear the data traces, but keep axises on.


Regards,

Zhu.



ZH Zhu March 28, 2023 01:52 AM UTC

Hi, Yuvaraj,


I got it, clearing the datasouces should be the way to go.


Regards,

Zhu.



ZH Zhu March 28, 2023 03:13 AM UTC

...

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.



YG Yuvaraj Gajaraj Syncfusion Team March 28, 2023 04:11 PM UTC

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.


Marked as answer

ZH Zhu March 29, 2023 03:00 AM UTC

Hi, Yuvaraj,


It works, thank you so much for the help.


Best Regards,

Zhu.



YG Yuvaraj Gajaraj Syncfusion Team March 29, 2023 04:45 AM UTC

Most Welcome. Kindly get back to us if you have further queries. We are always happy to assist you.


Loader.
Live Chat Icon For mobile
Up arrow icon