BarChart
One series over time, such as calls per day. Accent columns, a baseline, first and last labels, every value as text.
Examples
Calls per day
Hover a column for its value. Zero days keep their slot so the time axis stays even.
LightCalls per day, last 7 days
- Nov 6: 120
- Nov 7: 180
- Nov 8: 0
- Nov 9: 96
- Nov 10: 240
- Nov 11: 310
- Nov 12: 280
DarkCalls per day, last 7 days
- Nov 6: 120
- Nov 7: 180
- Nov 8: 0
- Nov 9: 96
- Nov 10: 240
- Nov 11: 310
- Nov 12: 280
<BarChart caption="Calls per day, last 7 days" data={days.map((d) => ({ label: d.label, value: d.calls }))} />Usage
import { BarChart } from '@switchboard/ui'
<BarChart caption="Calls per hour" captionHidden height={72} data={series} format={formatNumber} />Props
Every component also takes mix, for css() and mixins applied after its own style.
BarChart
| Prop | Type | Default | Description |
|---|---|---|---|
| data* | { label: string; value: number }[] | – | Columns, oldest first. Scaled to the largest value; one series only. |
| caption* | string | – | Names the chart; also the accessible name of the list of bars. |
| captionHidden | boolean | – | Hide the visible caption when a card header already names the chart. |
| height | number | – | Plot height in px. Default 96. |
| format | (value: number) => string | – | Formats values in the hover titles and the text alternative. |
Also accepts every <figure> attribute.
Accessibility
- The bars are an <ol> named by the caption; each <li> has its label and value as visually hidden text, so screen readers read the series as a list.
- Each column also has a title, so pointer users get the value on hover without a script.
- Identity is never colour alone: there is one series and its name is the caption.
Guidance
Do
- Pair it with a table of the same numbers when people need to compare exact values.
- Keep empty periods so the time axis is even.
Don’t
- Plot two measures with different scales on one chart.
- Use it for categories with no order; use a table or TokenMeter.