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
Flagged
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
| Variant | What it is |
|---|---|
| default | Primary line. |
| flagged | Pass 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
| Prop | Type | Default | Description |
|---|---|---|---|
values * | number[] | — | number[]; at least two values, otherwise nothing renders |
width | number | 72 | Width in px |
height | number | 22 | Height in px |
color | string | var(--co-primary) | CSS colour, use a token (`var(--co-danger)` for a flagged value) |
label | string | "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>
| Kind | Name | Description |
|---|---|---|
| property / JSON attribute | values | number[]; at least two values, otherwise nothing renders |
| attribute | width | Width in px; default 72 |
| attribute | height | Height in px; default 22 |
| attribute | color | CSS colour, use a token (`var(--co-danger)` for a flagged value); default var(--co-primary) |
| attribute | label | Start of the accessible name, followed by the values; default "Trend" |
| attribute | type | |
| attribute | name | |
| property / JSON attribute | max | |
| property / JSON attribute | min |