Components / data
Sparkline
The shape of a series, small enough to sit in a table cell or beside a number.
Summary
The shape of a series, small enough to sit in a table cell or beside a number.
| APG pattern | none |
| Built on | native elements |
| Status | self-tested |
| Since | 0.16.0 |
<Sparkline values={[310, 290, 345, 330, 380, 402]} label="Dining, last 6 months, rising" />
<Sparkline size="sm" values={[118, 121, 117, 119]} label="Transit, last 4 months, steady" />
Anatomy
A <span data-se="sparkline"> carrying the image role and its name. Inside it, line is a drawing whose points are percentages of the frame, and mark is a dot on the last value.
| Part | Element | Required |
|---|---|---|
line | <svg> | no |
mark | <span> | no |
Properties
| Property | Values | Default | What it does |
|---|---|---|---|
values | number[] | required | The series, in order. Measured from zero, so height means amount. With fewer than two values there is no line to draw: the frame keeps its size and its name, and draws nothing. |
label | string | required | Its name: what is measured and which way it went — Dining, last 12 months, rising. Not drawn. A line alone cannot be read by a screen reader, so this is the finding. |
size | sm · md | md | The frame. sm sits on a line of interface text, in a table cell; md sits beside a heading or a stat. |
States
_None. Rest is the only condition it has._
Behavior
The line spans the frame. The first value sits at the start edge and the last at the end edge, whatever the count.
It is measured from zero. The scale runs from zero to the largest value, so height means amount and a flat series draws flat. A series that goes below zero takes its lowest value as the floor.
Fewer than two values is not a line. The frame keeps its size and its name, and draws nothing.
Accessibility
The trend is said in words. label is the accessible name, and it carries what the drawing shows. A line alone cannot be read by a screen reader.
Keyboard
None of its own. It is not focusable and takes no keys.
Roles, states and properties
| Attribute | Set by |
|---|---|
aria-hidden | always true |
aria-label | set at render |
role | always img |
Focus
Never takes focus. It reports a shape and offers no action.
Screen reader
Not recorded as verified. Stage 4 of the readiness ladder — driving each component with VoiceOver and NVDA — is unstarted across the package, and no component should claim otherwise until docs/journal/ records the session that did it.
Contrast and target size
npm run check:contrast audits every color pair this component uses across all four skins, light and dark, and fails the build on a shortfall. Two waivers are on the record in docs/audit/DEFERRED.md.
It sets no target size of its own; anything interactive inside it brings its own.
The line and the mark are --se-series-1, which check:contrast holds to 3:1 on --se-surface.
Tested
test/apg/sparkline.test.jsxtest/browser/sparkline.spec.mjs
Known gaps
_No upstream requirement is recorded as not applicable._
Appearance
The frame is as tall as the icon box that sits on the same line: --se-icon-lg at md, --se-icon-md at sm. It is four times as wide; the ratio is a local, --se-_ratio, as Frame's is. The line is a hairline and a half, held at that width however the frame stretches. The mark is --se-space-1 across.
| Token | Used for |
|---|---|
--se-border-width | stroke-width |
--se-icon-lg | block-size |
--se-icon-md | block-size |
--se-radius-pill | border-radius |
--se-series-1 | background, stroke |
--se-space-1 | block-size, inline-size, margin |
Motion
Nothing moves. The line never draws itself in: data is not decoration.
Content
The label says what is measured and which way it went. Dining, last 12 months, rising. Never the word sparkline, and never the values read out one by one.
Usage
Not for reading a value. Write the number beside it, or use a Chart.
Not for comparing two series. Two lines in one small frame cannot be told apart. Use a Chart.
sm in a table cell, md beside a heading or a stat. The frame takes its height from the icon box of the text it sits beside, so it lines up without a rule of the caller's.
Notes
The color is --se-series-1, not --se-accent. They are the same value unless a skin separates them. A sparkline is a data mark, and the series scale is the name for that job.
No color for the direction of the trend. Whether up is good depends on what is measured. The caller knows; the line does not. Meter refuses the same thing.
The mark is a span, not a circle in the drawing. The drawing stretches to the frame, and a circle in a stretched box is an oval. The span is placed by the same two percentages and stays round.
It is turned over on a right-to-left page, so the first value is always at the start of the reading direction. The direction is read from the dir attribute: the build lowers :dir(rtl) to a list of languages, which misses a page that sets dir with no lang.
The sizes come by way of tokens. The prototype it was built for drew 64 by 18 and 96 by 24. In davor-anic the two icon boxes are 18 and 24, so the heights match and the widths are 72 and 96.