Sparkline
Slant / Data
A tiny line chart of a series, for a trend beside a number.
Demo
Usage
import { Row, Sparkline, Text } from '@tuttn/slant'
// A label makes it an image for screen readers. Name the trend, not the numbers.
<Sparkline series={[3, 5, 4, 8, 7, 9, 12]} label="Sessions this week, rising" />
// Any size in pixels; the line stretches to fill it.
<Sparkline series={series} width={240} height={48} label="Sessions this week, rising" />
// Without a label it is decorative, for a line beside text that already says it.
<Row gap={12}>
<Text variant="mono">48 sessions</Text>
<Sparkline series={series} />
</Row>Props
| Prop | Type | Default | Description |
|---|---|---|---|
series | number[] | — | The values, oldest first; the line spans their range. |
width | number | 96 | The rendered width in pixels; the line stretches to fill it. |
height | number | 32 | The rendered height in pixels. |
label | string | — | Announced to screen readers as an image; without it the line is decorative. |
…rest | SVGAttributes<SVGSVGElement> | — | className, other attributes and the ref go on the svg. style is merged over the width and height. |
Accessibility
- With
label, the svg hasrole="img"and the label as its name. Say what the trend means ("Sessions this week, rising"); the points themselves aren't read. - Without
label, the svg isaria-hidden. Use that only when nearby text carries the data, as StatCard does. - It has no focus, hover or tooltips. For values people need to read, use a BarChart or a Table.
- The draw-in stops under
prefers-reduced-motion, and the line appears already drawn.
The line spans the series' own range: its lowest value sits at the bottom and its highest at the top, so it shows the shape of a trend, not its scale. A flat series draws along the bottom. The stroke is the theme's accent and stays 1.6px wide at any size. A new series replays the draw-in.