Skip to content

Sparklines ​

The spark renderers draw a small chart in one cell. They suit showing a trend at a glance. There are three, and all need the optional renderers bundle.

KeyWhat it draws
sparklineA line (curve, area, marker dots)
sparkbarsBars (negatives go down, one bar can be emphasized)
sparkwinlossEqual-height win (up), loss (down) and draw (thin bar) marks, whatever the size
ts
{ id: 'trend', cellRenderer: 'sparkline', cellRendererParams: { curve: 'smooth', area: true, marks: ['last', 'max'] } },
{ id: 'sales', cellRenderer: 'sparkbars', cellRendererParams: { highlight: 'last' } },
{ id: 'form',  cellRenderer: 'sparkwinloss', cellRendererParams: { when: (v) => (v > 0 ? 'win' : v < 0 ? 'loss' : 'draw') } }

If the cell value is an array of numbers (or text split by commas or spaces such as '1, 3, 2'), it is drawn as is. Anything that is not a number, and any number above 1e15 in size, is skipped. With too few values (fewer than 2 for a line or bars, none for win/loss) a dash (—) is shown.

Common options ​

OptionValueDefaultEffect
values({ row, rowKey, columnId, value }) => number[]cell valueChoose the values yourself; null means no values
height4-10020Height in px, capped at row height minus 4px
width8-1000 or 'fill''fill'A number is the width in px; 'fill' stretches to the cell width
tone'info' · 'success' · 'warning' · 'danger' · 'muted''info'Color (a token, so dark mode follows)
min, maxnumber (within ±1e15)from dataFix the axis; with both, min must be smaller
maxPointsinteger 2-1000120Only the last N points are drawn
title({ ... }) => stringsummary textAccessible name; default is text like "5 values, min 1, max 9, last 4" in the grid language

Per-renderer options ​

Option (sparkline)ValueDefaultEffect
curve'linear' · 'smooth''linear'smooth is a smooth curve through the points (it does not overshoot the range)
areabooleanfalseFill lightly under the line
strokeWidth0.5-61.5Line width in px
marksarray of 'first' · 'last' · 'min' · 'max'['last']Where to draw dots; an empty array draws none
Option (sparkbars)ValueDefaultEffect
gap0-101Gap between bars; with many bars it uses at most 40% of the width
negativeTonetone'danger'Color of negative bars; 0 is the baseline
highlight'last' · 'min' · 'max' · nullnullThat bar is strong and the others are dimmed
Option (sparkwinloss)ValueDefaultEffect
winTone, lossTonetonesuccess, dangerWin and loss colors; a draw is a thin muted bar
when(value) => 'win' | 'loss' | 'draw'by signDefault: above 0 is a win, below 0 a loss, 0 a draw
gap0-101Gap between bars

An option the renderer does not have, such as curve on bars, is an invalid-option when the grid is created.

Accessibility, performance and export ​

  • Each chart is one <svg role="img" aria-label="…">. Assistive technology reads the summary text (or title). The summary includes the minimum, maximum and last values so meaning is not carried by color alone.
  • The SVG is built only with DOM calls (values are never put into HTML). When a cell is reused, only the inside of the same <svg> changes; no layout is read and the work is proportional to the number of points. There is no animation.
  • With width 'fill' the picture stretches to the cell width; line thickness and marker dots do not stretch.
  • Export (CSV and Excel) reads the cell value; chart text is not exported.
  • If values, title or when throws, the error is reported through the error event (callback-error) and the default is used (no values, the summary text, the sign rule).

For drawing with a custom renderer, see Built-in or your own.