Skip to main content

Sparkline

BasicCharts<co-sparkline>

Sparkline is a tiny trend line for a vital sign or lab value, with the last point marked.

import { Sparkline } from 'health-components';

Examples​

Showcase​

Storybook

Flagged​

Storybook

Usage​

<Sparkline values={[7.9, 7.4, 7.1, 6.8]} />

When to use​

  • Inline trend next to a value.

When not to use​

  • Any chart that needs axes: LineChart.

Variants and states​

VariantWhat it is
defaultPrimary line.
flaggedPass color var(--co-danger).

Accessibility​

  • role img with all values in the label.

Do and don't​

  • Do: Pair with the number.
  • Don't: Use alone.

Props​

PropTypeDefaultDescription
values *number[]—number[]; at least two values, otherwise nothing renders
widthnumber72Width in px
heightnumber22Height in px
colorstringvar(--co-primary)CSS colour, use a token (`var(--co-danger)` for a flagged value)
labelstring"Trend"Start of the accessible name, followed by the values

Also accepts native attributes, including type, name, max, min, plus className and event handlers on the root element.

Angular, Vue and HTML​

Register the elements once (Angular guide), then use <co-sparkline>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.

Angular template
<co-sparkline width="…" height="…" [values]="values"></co-sparkline>
KindNameDescription
property / JSON attributevaluesnumber[]; at least two values, otherwise nothing renders
attributewidthWidth in px; default 72
attributeheightHeight in px; default 22
attributecolorCSS colour, use a token (`var(--co-danger)` for a flagged value); default var(--co-primary)
attributelabelStart of the accessible name, followed by the values; default "Trend"
attributetype
attributename
property / JSON attributemax
property / JSON attributemin