fromLineChartData static method
Returns the legend entries to display for data, following these
rules in order:
- If
data.legendis non-empty, returns it verbatim (wrapped in an unmodifiable view) so user-specified entries always win. - Otherwise, when the chart has more than one series
(
series.length + functionSeries.length > 1), auto-derives one entry per series from each series' name and color. - Otherwise (zero or one series and no explicit legend), returns an empty list — single-series charts don't need a legend.
Implementation
static List<LegendEntry> fromLineChartData(LineChartData data) {
if (data.legend.isNotEmpty) return List.unmodifiable(data.legend);
final totalSeries = data.series.length + data.functionSeries.length;
if (totalSeries > 1) {
return List.unmodifiable([
for (final s in data.series) LegendEntry(label: s.name, color: s.color),
for (final f in data.functionSeries)
LegendEntry(label: f.name, color: f.color),
]);
}
return const [];
}