Sparkline

A tiny line chart that shows the shape of a series in the space of a word. Use it in tables, cards and stats, next to the number it explains.

General

Pass the values in data. Give it an aria-label that says what it shows, or it stays hidden from screen readers.

Trend color

With trend, the color follows the change from the first to the last value: success when it rises, error when it falls.

Types and colors

Use type for a theme color, or color for any CSS color. Turn the area off with area={false}.

Missing values

A null breaks the line. Use connectNulls to draw through it.

APIs

Sparkline.Props

AttributeDescriptionTypeAccepted valuesDefault
datathe values to draw, a null leaves a gapArray<number / null>--
typetheme color of the lineNormalTypes'default', 'primary', 'secondary', 'success', 'warning', 'error', 'info'primary
colorany CSS color, replaces type and trendstring--
trendcolor by the change from the first to the last valueboolean-false
areafill the area under the lineboolean-true
strokeWidththickness of the line, in pixelsnumber-2
connectNullsdraw the line through null valuesboolean-false
...native props, passed to the svgSVGAttributes'aria-label', 'className', ...-

Ref

The ref points at the svg.

Accessibility

A sparkline has no text, so describe what it shows with aria-label or aria-labelledby, including the direction, such as "Weekly visits, rising". With a name it is an image. Without one it is hidden from assistive technology, which suits a chart that sits next to the same number in text.

Edit this page on GitHub