Sparkline

Slant / Data

A tiny line chart of a series, for a trend beside a number.

Demo

Usage

@tuttn/slant
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

PropTypeDefaultDescription
seriesnumber[]—The values, oldest first; the line spans their range.
widthnumber96The rendered width in pixels; the line stretches to fill it.
heightnumber32The rendered height in pixels.
labelstring—Announced to screen readers as an image; without it the line is decorative.
…restSVGAttributes<SVGSVGElement>—className, other attributes and the ref go on the svg. style is merged over the width and height.

Accessibility

  • With label, the svg has role="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 is aria-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.