Charts topic
Draw a Chart over a worksheet range and add it with Sheet.addChart. A chart
plots one or more ChartSeries; the factory you pick sets the type: column, bar,
line, area, pie, doughnut, scatter, or radar. Charts in an opened file are read
back through Sheet.charts.
// Category labels in A2:A4, values in B2:B4.
sheet.addChart(Chart.column(
anchor: CellIndex.indexByString('D2'),
title: 'Quarterly sales',
categories: 'A2:A4',
series: [ChartSeries(name: 'Sales', values: 'B2:B4')],
));
for (final c in sheet.charts) {
print('${c.type} with ${c.series.length} series');
}
Print values (or the category, series name, or percentage) on the plot with
ChartDataLabels:
sheet.addChart(Chart.pie(
anchor: CellIndex.indexByString('D2'),
categories: 'A2:A4',
series: ChartSeries(values: 'B2:B4'),
dataLabels: ChartDataLabels(percent: true),
));
Colour a whole series with ChartSeries(color: ...), or individual pie/doughnut
slices with ChartSeries(pointColors: [...]); anything left unset uses a
built-in Office palette. See ChartType, ChartGrouping, LegendPosition, and
RadarStyle for the remaining options.
Classes
- Chart Charts
- A chart anchored to a worksheet cell, authored over data ranges.
- ChartDataLabels Charts
-
What a chart prints on its data labels, the small text drawn on each point,
bar, or slice. Pass one to a Chart via
dataLabels; omit it for none. - ChartSeries Charts
- One data series in a Chart: a values range plus an optional name and, for scatter charts, an x-values range.
Enums
- ChartGrouping Charts
- How multiple series are combined (ignored by pie/doughnut/scatter).
- ChartType Charts
- The kind of chart to render.
- LegendPosition Charts
- Where the legend sits, or none to hide it.
- RadarStyle Charts
- The visual style of a radar Chart (ignored by other chart types).