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.
| Key | What it draws |
|---|---|
sparkline | A line (curve, area, marker dots) |
sparkbars | Bars (negatives go down, one bar can be emphasized) |
sparkwinloss | Equal-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
| Option | Value | Default | Effect |
|---|---|---|---|
values | ({ row, rowKey, columnId, value }) => number[] | cell value | Choose the values yourself; null means no values |
height | 4-100 | 20 | Height in px, capped at row height minus 4px |
width | 8-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, max | number (within ±1e15) | from data | Fix the axis; with both, min must be smaller |
maxPoints | integer 2-1000 | 120 | Only the last N points are drawn |
title | ({ ... }) => string | summary text | Accessible name; default is text like "5 values, min 1, max 9, last 4" in the grid language |
Per-renderer options
Option (sparkline) | Value | Default | Effect |
|---|---|---|---|
curve | 'linear' · 'smooth' | 'linear' | smooth is a smooth curve through the points (it does not overshoot the range) |
area | boolean | false | Fill lightly under the line |
strokeWidth | 0.5-6 | 1.5 | Line width in px |
marks | array of 'first' · 'last' · 'min' · 'max' | ['last'] | Where to draw dots; an empty array draws none |
Option (sparkbars) | Value | Default | Effect |
|---|---|---|---|
gap | 0-10 | 1 | Gap between bars; with many bars it uses at most 40% of the width |
negativeTone | tone | 'danger' | Color of negative bars; 0 is the baseline |
highlight | 'last' · 'min' · 'max' · null | null | That bar is strong and the others are dimmed |
Option (sparkwinloss) | Value | Default | Effect |
|---|---|---|---|
winTone, lossTone | tone | success, danger | Win and loss colors; a draw is a thin muted bar |
when | (value) => 'win' | 'loss' | 'draw' | by sign | Default: above 0 is a win, below 0 a loss, 0 a draw |
gap | 0-10 | 1 | Gap 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 (ortitle). 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,titleorwhenthrows, the error is reported through theerrorevent (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.
Gallery example: spark-line-builtin
Gallery example: spark-bars
Gallery example: spark-winloss
Gallery example: renderer-sparkline