Skip to the content

Sparkline

A word-sized line of a series — a trend next to a number, with no axes and no labels. It strokes in currentColor from a theme token, so it works in light and dark for every brand.
Data Display

When to use

Use when
  • Showing where a value has been going, beside the value itself: a score per week, cost per run.
  • Dense rows and cards where a chart with axes does not fit.
Avoid when
  • The reader needs the numbers, the scale or several series — use a chart or a table.
  • One measurement on a scale — use Meter.
  • Task progress — use ProgressBar.

Usage

0.79
import { Sparkline } from '@apollion-dsi/core/data-display/sparkline';

<Sparkline values={[0.61, 0.64, 0.7, 0.68, 0.74, 0.79]} label="Fitness over 6 weeks, rising" />;

values is the series, oldest first. Non-finite values are dropped; fewer than two points render nothing. The default box is 64 × 20 px (width, height).

Colour

The line never guesses whether a rise is good news. Without color or higherIsBetter it stays neutral (ink.secondary).

  • higherIsBetter compares the last point with the first: true paints a rise success and a fall danger; false reverses it. A flat series stays neutral.
  • color is a theme token and wins over higherIsBetter. Never a raw colour.
<Sparkline values={fitness} label="Fitness over 5 weeks, rising" higherIsBetter />
<Sparkline values={cost} label="Cost per run over 5 days, rising" higherIsBetter={false} />
<Sparkline values={runs} label="Runs per day, last 5 days" color="information" />

Accessibility

The SVG is role="img" named by label. Say the direction in the label (…, rising): colour alone never carries the meaning.

Properties

Beyond the props above, Sparkline accepts the native <span> attributes and the grid placement props (area, alignSelf, justifySelf), so it can sit in a Grid slot directly.

See also