Skip to content
EspañolEnglish
All components (283)

Waffle chart

Data · WaffleChart · .amset-waffle

What it is and when to use it

A grid of squares in which each one is worth the same: a hundred squares, and 46 % are of this tone. It reads better than a ring when what matters is "how many out of a hundred", because there are no angles to compare by eye.

When to use it

  • A few parts of a total, said as a percentage ("out of every hundred orders, 46 come through the web").
  • items are the parts: { key, label, value, tone? }. rows and columns change the grid (10 × 10 by default) and total says what it is worth when full: if it is larger than the sum, what is missing stays empty.
  • The cells are split by the largest-remainder method: they add up to exactly the ones there are.
  • Pointing at a row of the legend highlights its cells and dims the rest.

When not to

  • Many parts: TreemapChart.
  • Evolution over time: LineChart.
  • A single measure against a ceiling: RingProgress or Gauge.

Keyboard: Tab goes to the drawing and the arrows move from part to part; the marked part dims the rest, with a spoken notice.

Accessibility: it is an image (role="img") with a written summary ("4 parts out of 100. The largest, Web: 46, 46 %") and underneath goes a real table. The numbers are written in the legend: colour is not the only thing that informs.

Fine-tuning: --amset-waffle-cell is the side of each square, --amset-waffle-gap the gap and --amset-waffle-empty the colour of the empty ones.

What it looks like

Use the arrow keys to move through the values, Home and End to jump to the first and last, and Escape to leave.
Orders by channel
PartValueShare of total
Web4646%
Store3131%
Phone1515%
Others88%

<WaffleChart
  label="Orders by channel"
  items={[
    { key: "web", label: "Web", value: 46 },
    { key: "store", label: "Store", value: 31 },
    { key: "phone", label: "Phone", value: 15 },
  ]}
/>

Props

Import it with import { WaffleChart } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
itemsrequiredreadonly WaffleItem[]The parts: `{ key, label, value, tone? }`.
labelrequiredstringWhat is being measured. Required: a chart without a title tells nothing.
classNamestringMerged with the library classes; it does not replace them.
columnsnumber—
errorReactNodeThe data has not arrived: it says so where the drawing goes, with what is passed here.
format(value: number) => string—
loadingbooleanThe data is on its way.
rowsnumber—
tableVisiblebooleanAlso shows the table. For the screen reader it is always there.
totalnumberWhat the full grid is worth. Without it, the sum of the parts; if it is larger, what is missing stays empty.

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

CSS variables

These CSS variables are how you adapt it. Declare them on the component's selector, not on :root: the stylesheet redeclares them in the rule itself, and a declaration on the same element always wins.

VariableDefault
--amset-waffle-cell1.5rem
--amset-waffle-gap3px
--amset-waffle-emptyvar(--amset-border)

How to change it

.amset-waffle {
  --amset-waffle-cell: ...;
  --amset-waffle-gap: ...;
}

In the test bench

Every state and variant, to try one at a time, on its page at storybook.amsetui.com: