Sparklines
A sparkline group is a worksheet object that shows small in-cell charts without holding cell values. This page covers each group's fields, source references and members.
What you can do
- Read sparkline groups and their source references: Reading sparkline groups, Source references.
- Add, update and remove sparkline groups: Adding, updating and removing groups.
Reading sparkline groups
ws.listSparklineGroups() lists the x14:sparklineGroups of a sheet's worksheet extension list in document order. A SparklineGroup carries these fields:
| Field | Meaning |
|---|---|
type | A SparklineType: Line, Column, Stacked |
| Colours | The series, negative, axis, marker, first, last, high, and low colours |
| Toggles | The matching markers, high, low, first, last, and negative toggles |
displayXAxis, displayHidden | Axis and hidden-cell display |
minAxisType, maxAxisType, manualMin, manualMax | The axis scaling |
dateAxis, dateAxisRange | The date axis |
lineWidthPt | The line width in points |
emptyCellsAs | A BlanksAs: Zero, Gap or Span; an absent attribute reads as Zero |
sparklines | The group's sparklines |
A colour whose kind is ColorKind.None is absent, and manualMin / manualMax are null when the bound is not set.
Each Sparkline is a data source and the location cell that shows it. Reads and inputs differ as follows:
| Field | Read as | Input accepts |
|---|---|---|
source | A SheetRect, or null when the stored range text does not parse, in which case the stored text is kept for a round trip | A SheetRect or a sheet-qualified A1 range (an unqualified one resolves on the receiving sheet) |
location | A CellAddress | A CellAddress or an A1 cell |
dateAxisRange | A SheetRect, null when the group has none or its stored text does not parse | A SheetRect, an A1 range or null |
Source references
A sparkline source and a group's dateAxisRange are one reference or defined name, as in Excel. addSparklineGroup and updateSparklineGroup treat them as follows, and Excel refuses a workbook holding a refused form:
| Input | Result |
|---|---|
| One reference or defined name | Accepted |
| A 3-D span, or another workbook's range | Accepted |
#REF! | Accepted; stored as a sparkline without a source |
null | Stores a sparkline without a source |
A union, a structured reference, an expression, or a sheet-qualified #REF! | StatusCode.InvalidArgument |
| Empty text | StatusCode.InvalidArgument |
Adding, updating and removing groups
ws.addSparklineGroup(spec) appends a group and returns its id (a SparklineGroupId). spec.sparklines must hold at least one sparkline, and any other field left out takes the default of a new line group.
ws.updateSparklineGroup(group, patch) is a partial update; group is an id or a position. A key left out keeps its value. null clears manualMin, manualMax, dateAxisRange and the eight colours, and no other key accepts it (it is a TypeError). A record from listSparklineGroups() can be passed back.
An update rewrites the modelled attributes, colours, and date range, and keeps the group's unmodelled attributes and children (uid, unknown extensions). rightToLeft plots the group's first point at the right edge and is read from and written to .xlsx and .xlsb. A spec.sparklines replaces the group's sparklines and must not be empty; leaving it out keeps them.
ws.removeSparklineGroup(group) removes a group.
A group's id is opaque and stays valid while the workbook is open, whatever is added or removed or whichever rows move; it is assigned again on load. A number is a position and shifts when a group is added or removed. An unknown id throws StatusCode.NotFound.
Switch a sparkline group to another type and change a shape's preset and text in the sheet below.
Change a sparkline type and a shape in place
H2:H4 will hold one sparkline per region over B2:G4. An existing sparkline group or shape can be edited without being drawn again.
Powered by the real Formulon engine (WASM) — it runs entirely in your browser, nothing is uploaded.
Sparkline saving and bindings
Sparkline groups are written to .xlsb; a group loaded from .xlsx whose source is one Excel cannot store there fails the save with StatusCode.IoFeatureNotWritable.
Python uses list_sparkline_groups(), add_sparkline_group(), update_sparkline_group() (keyword-only, defaulting to UNCHANGED), and remove_sparkline_group().
The C calls are:
fm_sheet_get_sparkline_group_countfm_sheet_get_sparkline_group_atfm_sheet_get_sparkline_group(by id)fm_sheet_get_sparkline_atfm_sheet_add_sparkline_groupfm_sheet_update_sparkline_group, whoseitemsargument replaces the sparklines, andNULLkeeps themfm_sheet_remove_sparkline_group