Controller updateDataSource removedDataIndexes

Hello,
I have problem with removing multiple indexes, on the start i have:

List<ChartData> dataSource = List.generate(
7,
(index) => ChartData(index, Random().nextDouble() * 100),
);

after making this:

dataSource.removeRange(1, 5);
controllers?.updateDataSource(removedDataIndexes: [1, 2, 3, 4]);

i got error:

RangeError (length): Invalid value: Not in inclusive range 0..3: 4
I just want to remove indexes in range



Attachment: lib_41667ed4.zip

1 Reply

AS Aswini Suresh Reddy Syncfusion Team March 3, 2025 12:35 PM UTC

Hi arTree Company,


We would like to let you know that the range error can be avoided by checking the length of dataSource before removing indexes and updating them. You can remove a range of indexes using a for loop to ensure proper removal and update the data points (indexes) for FastLineSeries using the removedDataIndex property in updateDataSource. We have attached the sample below for your reference. 


List<int> removeIndexes = [1, 2, 3, 4];

  void _removeValuesFromChart() {

    for (int index in removeIndexes) {

      if (index < chartData.length) {

        // Check if the index exists

        chartData.removeAt(index);

        controllers?.updateDataSource(removedDataIndex: index);

      }

    }

  }


Please check and get back to us if you require further assistance. 


Regards, 
Aswini S


Attachment: fr_196254_ecf3a320.zip

Loader.
Up arrow icon