Sparkline
A small line chart, for a trend next to a number
Preview
Bookings this week468 more
Use
The code of the preview above
import { Row, Sparkline, Stat, Trend } from '@/components/ui';
<Row gap={4} nowrap>
<Stat label="Bookings this week" value="46" note={<Trend direction="up">8 more</Trend>} />
<Sparkline label="Bookings per week, rising" values={[12, 18, 15, 22, 28, 26, 34, 46]} />
</Row>Options
| Option | Type | What it does |
|---|---|---|
label Needed | string | What the line shows, for screen readers. |
values Needed | number[] | The numbers, oldest first; the line runs from the lowest to the highest. |
area | boolean · default true | Fill the area under the line. |
It also takes the 486 attributes of the element or UI SDK part it draws: className, aria-label, events and the rest.
Without React
The same look on any HTML, with the classes svg.ui-sparkline.
With the CSS in parts (/ui/css/), it needs these, besides the ones every page loads:
components/charts.cssIn the examples
Small screens made with it and the rest of the kit. They work: click, type and choose in them.
Sales€4,12012% on October
Orders968 more
Returns32 fewer
This week, by product
| Linen tote | 18% | |
| Enamel mug | 9% | |
| Wall calendar | 44% | |
| Sticker sheet | 2% |
Showing things: states, do and don’t
A small line chart next to a number.
States. Lists, tables and boards have three more states besides their content: empty (Empty, with the first action inside), loading (Skeleton) and failed (Alert tone="danger"). A chosen row shows in ink, never in the brand colour.
Do
- Put numbers, dates and codes in
ui-mono(in a table cell,ui-num, which also aligns them). - Let a
Tableturn into blocks on a phone; give itscrollonly when it is read down its columns. - Show a status in words and colour together (
Badge tone="success"with "Paid"), never colour alone.
Don't
- Don't put a card round a
Table,List,Cells,CalendarorEmpty: they draw their own box. - Don't truncate a name or a price to fit; let it wrap. Truncate only file names and addresses.
- Don't use the status colours (success, warning, danger, info) for anything but those meanings.