Skip to content

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 ​

Reading sparkline groups ​

ws.listSparklineGroups() lists the x14:sparklineGroups of a sheet's worksheet extension list in document order. A SparklineGroup carries these fields:

FieldMeaning
typeA SparklineType: Line, Column, Stacked
ColoursThe series, negative, axis, marker, first, last, high, and low colours
TogglesThe matching markers, high, low, first, last, and negative toggles
displayXAxis, displayHiddenAxis and hidden-cell display
minAxisType, maxAxisType, manualMin, manualMaxThe axis scaling
dateAxis, dateAxisRangeThe date axis
lineWidthPtThe line width in points
emptyCellsAsA BlanksAs: Zero, Gap or Span; an absent attribute reads as Zero
sparklinesThe 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:

FieldRead asInput accepts
sourceA SheetRect, or null when the stored range text does not parse, in which case the stored text is kept for a round tripA SheetRect or a sheet-qualified A1 range (an unqualified one resolves on the receiving sheet)
locationA CellAddressA CellAddress or an A1 cell
dateAxisRangeA SheetRect, null when the group has none or its stored text does not parseA 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:

InputResult
One reference or defined nameAccepted
A 3-D span, or another workbook's rangeAccepted
#REF!Accepted; stored as a sparkline without a source
nullStores a sparkline without a source
A union, a structured reference, an expression, or a sheet-qualified #REF!StatusCode.InvalidArgument
Empty textStatusCode.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_count
  • fm_sheet_get_sparkline_group_at
  • fm_sheet_get_sparkline_group (by id)
  • fm_sheet_get_sparkline_at
  • fm_sheet_add_sparkline_group
  • fm_sheet_update_sparkline_group, whose items argument replaces the sparklines, and NULL keeps them
  • fm_sheet_remove_sparkline_group
  • Shapes — drawing shapes, text boxes and connectors.
  • Slicers — table slicers and the tables they filter.
  • Charts — read, create, and edit charts, and resolve their series against cell values.