compatibleChartTypesForConfig function

List<ChartType> compatibleChartTypesForConfig(
  1. BaseChartConfig config, {
  2. bool registeredOnly = true,
})

Suggest chart types that can consume config based on series-data shape.

Implementation

List<ChartType> compatibleChartTypesForConfig(
  BaseChartConfig config, {
  bool registeredOnly = true,
}) {
  final probe = Map<String, dynamic>.from(config.toJson());
  probe['type'] = chartTypeToString(config.type);
  if ((probe['series'] is! List) || (probe['series'] as List).isEmpty) {
    probe['series'] = config.series.map((s) => s.toJson()).toList();
  }
  if (config.xAxisConfig?.categories != null &&
      config.xAxisConfig!.categories!.isNotEmpty) {
    final existingXAxis = _stringKeyedMapOrEmpty(probe['xAxis']);
    probe['xAxis'] = {...existingXAxis, 'data': config.xAxisConfig!.categories};
  }
  return compatibleChartTypesForJson(probe, registeredOnly: registeredOnly);
}