Chart 4 of 15
Donut
Use it for a handful of parts that add up to one whole, when the share matters more than the exact amounts. Fold small slices into Other; more than six or seven slices want a bar list or treemap instead.
How to use it
const chart = donut({
parts: [
{ name: 'Housing', value: 1210, colour: catColor('Housing') },
{ name: 'Groceries', value: 438, colour: catColor('Groceries') },
{ name: 'Other', value: 164, colour: 'var(--c9)' }
],
centre: { value: '£1,812', label: 'September' },
size: 240,
onClick: part => openCategory(part.name),
label: 'Spending by category, September'
});Options
- parts
- [{ name, value, colour }]. Order is drawn clockwise from 12 o'clock.
- centre
- { value, label } shown in the hole until a slice is hovered or focused.
- size
- Pixel size of the square (default 220).
- fmt
- Formatter for the aria-label of each slice.
- onClick
- (part) => void.