Bar chart
A measure compared across categories — calls per site, failures per cause, minutes per region. Grouped, or stacked when the parts make a whole.
{/* Generated by scripts/build-component-docs.mjs — do not edit. The source is the component folder: guidance.json, the doc block and the props. Change those. */}
A measure compared across categories — calls per site, failures per cause, minutes per region. Grouped, or stacked when the parts make a whole.
Import
import { BarChart } from "@ir/ui";Watch out
- The bars are HTML, not SVG, and that is the point. The plot elsewhere is a 0–100 box stretched to its width, which is ideal for a line and wrong for a bar: stretching turns a 24px cap into whatever the container feels like and bends a 4px corner into an ellipse. As elements, a bar is capped at 24 exactly, its data-end is rounded 4 and its baseline end is square, and the 2px gap between touching marks is 2px. Only the gridlines stay SVG, and horizontal rules do not distort.
- Bars start at zero, always. A bar says "this much", and a bar chart with a cut-off baseline says it at four times the size.
yMinis not offered. - Stacked bars are for parts of a whole. Only the bottom segment and the total can be read along a common baseline; everything between floats. If the comparison people actually make is between the middle segments, group them instead.
Props
| Prop | Type | Required | What it does |
|---|---|---|---|
stacked | boolean | Parts of a whole, stacked on one baseline. Grouped when false. | |
yMax | number | Pin the top. The bottom is always zero. | |
label | string | yes | Sentence for the table caption. |
Do and don't
Start every bar at zero. Use a line chart if the interesting range is a narrow band well above it.
Don't — Cut the baseline to make a small difference look like a big one.
A bar encodes its value as length, so a cut baseline multiplies the difference by whatever the author chose. There is no yMin on this component for exactly that reason.
Stack only when the parts add to a total worth reading; group when the comparison is between the parts.
Don't — Stack series people need to compare with each other.
In a stack only the bottom segment and the grand total share a baseline. Every segment in between floats on the ones below it, so comparing two middles across columns is comparing two things that start in different places.
Leave the 24 cap alone; the gap between groups is what separates them.
Don't — Let bars grow to fill their slot, so a four-category chart is four slabs with no air.
The space is doing work — it is what makes a group read as one thing and the next as another. A bar that fills its slot turns a chart into a wall.
Let them truncate, or turn the chart on its side, or shorten the category names.
Don't — Rotate category labels to 45° to fit them in.
Angled text is measurably slower to read and the rotation grows with the category count, so the chart gets harder exactly as it gets busier. Truncation with the full name on hover keeps every label on one baseline.
Accessibility
- Like every chart here, the plot is
aria-hiddenand the numbers are carried by a visually-hidden table. - Each bar carries its own
title— series, category and value — so a pointer can read one without a crosshair. - A missing value leaves the slot empty rather than drawing a zero-height bar, which would be indistinguishable from a real zero.
- The 2px gap between touching bars is in the surface colour, so adjacent segments in a stack stay separable without a stroke.
Where it is drawn
Figma — structure from code, measurements from code.