Skip to content

PlSparkline

A chart with everything taken away except the shape. No axes, no grid, no legend, no tooltip, a word-sized picture that goes inside a sentence and says which way something has been going.

React
tsx
import { PlSparkline } from 'plass-ui';

<PlSparkline data={signups} endDot />;
dart
import 'package:plass_ui/plass_ui.dart';

PlSparkline(data: signups, endDot: true);

A sparkline is a different thing from a chart shrunk down. Every number it could label is one the surrounding text already has, which is why it labels none of them. Put it beside a PlStat, in a table cell, or in a line of prose.

Props

PropTypeDefaultDescription
data * readonly PlassChartDatum[]The values. A null is a gap here too
shape'line' | 'area' | 'bar''line'Which mark. A line for a trend, an area for a quantity, bars for a count of discrete things
curve'linear' | 'smooth' | 'step''linear'How the line gets from one point to the next
color'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info' | (string & {})'--plass-chart-1'The mark's colour, taken directly: one series and no legend, so there is nothing for a palette to hand out
endDotbooleanfalsePuts a dot on the last point that is a point — the one direct label a strip this small has room for
baselinenumberA rule across the strip: a target or a budget, the one piece of context a sparkline can carry
minnumberThe bottom of the scale. Left out, the strip fills itself with its own range
maxnumberAnd the top of it. Give a row of strips the same pair and they become small multiples
widthnumber | string'100%'How wide
labelstringA name for the strip. Without one it is taken off the accessibility tree entirely
sizeshared'xs' | 'sm' | 'md' | 'lg' | 'xl''md'How tall the strip is, sized against the line of text it sits beside rather than the page
PropTypeDefaultDescription
data * List<PlassChartDatum>The values. A null is a gap here too
shapePlSparklineShapePlSparklineShape.lineWhich mark. A line for a trend, an area for a quantity, bars for a count of discrete things
curvePlChartCurvePlChartCurve.linearHow the line gets from one point to the next
colorPlassColor?'--plass-chart-1'The mark's colour family. An exact colour goes to tint instead
tintColor?An exact colour, the other half of React's PlassColor | (string & {}) — Dart has no union
endDotboolfalsePuts a dot on the last point that is a point — the one direct label a strip this small has room for
baselinedouble?A rule across the strip: a target or a budget, the one piece of context a sparkline can carry
mindouble?The bottom of the scale. Left out, the strip fills itself with its own range
maxdouble?And the top of it. Give a row of strips the same pair and they become small multiples
widthdouble?'100%'How wide
semanticLabelString?A name for the strip. Without one it is taken off the accessibility tree entirely
sizesharedPlassSizePlassSize.mdHow tall the strip is, sized against the line of text it sits beside rather than the page

Unlike the full charts this one takes its colour directly. A sparkline has exactly one series and no legend, so there is nothing for a palette to hand out.

There is no tooltip and no legend, and adding either would make it a chart. A null is a gap here as everywhere, and the line breaks at it.

Examples

shape

React

The same three sentences the full charts say, at a size where nothing else is being said at all. A line for a trend, an area for a quantity, bars for a count of discrete things.

min and max

React

A sparkline scales itself to its own range, so the strip is always full. That is what makes it readable at twenty pixels tall, and it is also the trap: two of them side by side are drawn on two different scales, so a strip that climbs steeply may be the smaller number. Give a row of them the same min and max and they become a small-multiples chart instead.

baseline

React

A target, a budget, last year's average. The one piece of context a strip this small can carry. It is pulled into the range if it sits outside the data, so the rule is always visible.

endDot

Puts a dot on the last point that is actually a point, not on the last slot. It is the one direct label a strip this small has room for, and it says where the series ended up. Bars do not take it: a bar already ends where it ends.

Accessibility

  • Without a label the strip is taken off the accessibility tree entirely. A sparkline is decoration beside text that already carries the numbers, and an unlabelled image announced as an image is noise.
  • With a label it becomes a named role="img", and the values are written out beside it, clipped from view, never hidden from the tree. What a sparkline has to give a screen reader is the numbers, not a description of the shape they make.
  • Colour is never the only channel here either: a sparkline sits beside the name and the number it belongs to.

Released under the MIT License