Skip to content

BarChart

One series over time, such as calls per day. Accent columns, a baseline, first and last labels, every value as text.

DataServer-rendered

Examples

Calls per day

Hover a column for its value. Zero days keep their slot so the time axis stays even.

Light
Calls per day, last 7 days
  1. Nov 6: 120
  2. Nov 7: 180
  3. Nov 8: 0
  4. Nov 9: 96
  5. Nov 10: 240
  6. Nov 11: 310
  7. Nov 12: 280
Dark
Calls per day, last 7 days
  1. Nov 6: 120
  2. Nov 7: 180
  3. Nov 8: 0
  4. Nov 9: 96
  5. Nov 10: 240
  6. Nov 11: 310
  7. Nov 12: 280
Example
<BarChart caption="Calls per day, last 7 days" data={days.map((d) => ({ label: d.label, value: d.calls }))} />

Usage

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

BarChart props
PropTypeDefaultDescription
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.
captionHiddenboolean–Hide the visible caption when a card header already names the chart.
heightnumber–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.