Skip to content
Calm motion: animations on this site only fade, with no movement

Sparkline ​

A tiny inline chart for a row, a card or a sentence

A trend drawn at the size of a word: the last days of a metric in a table row, a stat card, a list item. It shows the shape, not the values, so pair it with the number it summarizes. For a chart the reader studies (axes, tooltips, several series) use Chart.

Line, bar and win/loss
MetricLast 9 daysShape
Visitsrising
Profitup and down
Results6 wins, 3 losses
  • type="line" (with fill and dot, if you want them). type="bar" grows from zero, so negatives hang below. type="winloss" ignores the size of a value and draws only whether it was up, down, or flat.
  • It is an image to assistive tech, named with a summary: the count, first and last value, low and high (or wins and losses for win/loss). Give it a label so it reads "Visits: 9 values, from 12 to 40…", and a format to put units on the numbers.
  • Color is a token name (chart-2, success, danger) or any CSS color. negativeColor colors the values below zero. Color is never the only signal: the bars sit above or below the line.
  • Size is in pixels (width, height). There is no hover, so nothing to reach by keyboard.

Usage ​

ts
import { BlessSparkline } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
data*number[]—
type"bar" | "line" | "winloss""line"`line`, `bar`, or `winloss` (every value drawn as a same-height win above or loss below the middle)
widthnumber120
heightnumber28
colorstring"chart-1"a token name (`chart-2`, `success`, `danger`…) or any CSS colour
negativeColorstring"danger"colour of values below zero in `bar` and `winloss`
fillboolean—line only: shade the area under the line
dotboolean—line only: a dot on the last value
labelstring—what is plotted; read with the summary by screen readers
format((v: number) => string)—text for one value in the summary, e.g. `(v) => v + " ms"`
minnumber—the bottom and the top of the scale, to put several sparklines on one scale
maxnumber—

Released under the MIT License. Character names and artwork belong to their owners.