onDataSourceSuccess method

  1. @override
Future<bool> onDataSourceSuccess(
  1. IDataSource source,
  2. Data? list
)
override

Called when the databroker returns a successful result

ChartModel overrides WidgetModel's onDataSourceSuccess to populate the series data from the datasource and to populate the label data from the datasource data.

Implementation

@override
Future<bool> onDataSourceSuccess(IDataSource source, Data? list) async {
  try {
    // here if the data strategy is category, we must fold all of the lists together and create a dummy key value map of every unique value, in order
    uniqueValues.clear();

    // clear data
    // pieData.clear();

    for (var serie in series) {
      // build the datapoints for the series, passing in the chart type, index, and data
      if (serie.datasource == source.id) {
        var points = serie.plotPoints(list);

        // add the built x values to a unique list to map to indeces
        uniqueValues.addAll(serie.xValues);

        pieData.addAll(points);

        serie.xValues.clear();
      }
    }

    notifyListeners('list', null);
  } catch (e) {
    Log().debug('Series onDataSourceSuccess() error');
    // DialogService().show(type: DialogType.error, title: phrase.error, description: e.message);
  }
  return true;
}