Sparkline
A chromeless trend line sized for a table cell, a list row or the trend slot of a c2-stat.
No axes, no grid, no legend, no tooltip and no card: the whole box is the data. c2-sparkline is an
inline-flex element 120×32px by default, which is the size a table cell, a list row or the trend slot of
a c2-stat actually has.
It takes the bare number[] shape as well as rows, which is usually all a cell has:
<c2-sparkline data="[3, 5, 4, 8, 6, 11]" tone="auto"></c2-sparkline>uPlot is what makes a sparkline per row affordable — the engine loads once for the page, and each instance is a single canvas.
Installation
npm install @c2n/chart uplotUsage
The values are a France 2015–2024 extract from the public Our World in Data Energy dataset, measured in terawatt-hours. The same extract drives every chart page; the sparkline simply removes the axes and surrounding chrome.
Tone
tone="auto" compares the last value with the first and paints the line with the positive or negative tone
— --c2-chart__tone-positive--color and --c2-chart__tone-negative--color. positive and negative force
one of them, and neutral (the default) keeps the series’ palette colour, which is what you want when the
sparkline sits next to other charts that share it.
A flat series, a series with fewer than two points, or a non-numeric end falls back to the palette colour rather than guessing a direction.
Sizing
The size is the API: --c2-chart--width (120px) and --c2-chart--height (32px), both redefined on the host
rather than merely defaulted, so an author rule on the element still wins. Padding is 0 and the border and
background are removed, so the line reaches the edges of the box.
c2-table c2-sparkline {
--c2-chart--width: 88px;
--c2-chart--height: 24px;
--c2-chart__line--width: 1px;
}What it leaves out, and putting it back
The axes, grid, cursor, legend and tooltip are switched off in the constructor rather than made impossible,
so a sparkline that does want a hover readout can set tooltip="axis" and cursor="x" back on. Series
children work too, when the row shape is what you have rather than a bare array.
Theming
The stroke colour, the two tone colours and everything else come from the shared --c2-chart__* namespace,
so a sparkline in a table and a line chart above it agree on colour
without any extra configuration.