Inserting Charts
Inserting charts
Add charts to a workbook: add data, build a chart with cell ranges, position it.
Supported types
column (vertical clustered), bar (horizontal), line, pie, doughnut, scatter
Core steps
Create a workbook & worksheet
Add data rows
Create a chart (using cell ranges)
Call
wb.addChart(chart)Anchor it (e.g.
twoCellAnchor)Generate files
Option summary (ChartOptions)
type
Chart type
One of: column, bar, line, pie, doughnut, scatter (default: column)
title
Chart title
Omit for no title
axis.x.title / axis.y.title
Axis labels
Ignored for pie/doughnut
axis.x.showGridLines / axis.y.showGridLines
Gridlines toggles
x = vertical lines, y = horizontal lines
axis.y.minimum / axis.y.maximum
Value axis bounds
Numbers (e.g. 0, 1)
stacking
Stack series
'stacked' or 'percent' (column / bar / line only)
width / height
Size (EMUs)
Usually omit (auto size)
categoriesRange
Category labels range
Not used by scatter (use scatterXRange instead)
series
Data series
Array of { name, valuesRange, color }
series[].scatterXRange
X values (scatter)
Only for scatter charts
dataLabels
Point label toggles
{ showValue, showCategory, showPercent, showSeriesName }
Quick start (multi‑series column chart)
Resizing (width & height)
Positioning
Position a chart with a two‑cell anchor (start & end grid cells):
Indices are zero‑based (0 = first column / row).
Legend
Auto behavior (no legend option provided): show legend only when there are 2 or more series.
You can override with the legend option:
Rules:
show: trueforces a legend even for 1 series.show: falsesuppresses legend even for multiple series.If
showis undefined, auto mode (2+ series) applies.overlayemits<c:overlay val="1">when true; otherwise0.
Note: Pie / Doughnut with multiple series produces multiple pies/rings; legend lists series names.
Data Labels
Provide high-level toggles for what text appears on each point.
API flags:
Behavior:
Pick the parts you want (value, percent, category, series name). Omitted = hidden.
Omit
dataLabelscompletely for none.Hover tooltips are unchanged (Excel shows full details on hover).
Examples:
Value-only on a column chart:
Percent-only on a pie (concise slice labels):
Value + percent on a doughnut:
Series name only (multi-line chart where legend is hidden):
Full example (pie with percent only):
Example (legend will show 2 entries and be placed top-right):
Troubleshooting
Missing chart
Not added to workbook
Call wb.addChart(chart)
No legend
Only one series
Add a second series
Axis titles missing
Using pie chart
Pie charts have no axes
Wrong data
Typo in range string
Check sheet name & $A$1 format
Minimal example
That's it — build your workbook and open in Excel.
Stacked & Percent Stacked
Enable stacking on multi-series column, bar, or line charts:
Notes:
Stacking applies only to column, bar, line.
Percent stacking rescales each category to 100%.
Chart Type Examples
Below are small, focused snippets for each type. They assume you already created a workbook (wb) and worksheet (ws) with matching ranges.
Column
Bar (horizontal)
Line
Pie (single series for one pie)
Doughnut (single series for one ring)
Scatter (X/Y numeric ranges)
Column Stacked
Column Percent Stacked
Line Stacked
Line Percent Stacked
Bar Stacked
Bar Percent Stacked
End of chart type examples.
Series Colors
Format: opaque ARGB FFRRGGBB (examples: FFFF9933 = orange, FF3366CC = blue).
Effects:
Column / Bar: fill color
Line / Scatter: stroke color
Pie / Doughnut: ignored (Excel auto colors slices)
Notes:
Alpha (anything other than
FF) is ignored; colors are always rendered fully opaque.Invalid strings are ignored silently.
Theme colors are not supported; supply an ARGB hex.
Cell Range Cheat Sheet
3 category labels
Sheet!$A$2:$A$4
Sales!$A$2:$A$4
Series values
Sheet!$B$2:$B$4
Sales!$B$2:$B$4
Scatter X values
Sheet!$A$2:$A$21
Runs!$A$2:$A$21
Scatter Y values
Sheet!$B$2:$B$21
Runs!$B$2:$B$21
Tips:
Always use absolute refs (
$A$1) so range stays stable.Category and each series range must have the same number of rows.
Last updated