Pie and donut chart
Part of a whole: slices sorted by size, folded into “Other” past six, each share written in the legend; a donut carries the total in its hole.
- Domain
- Data display
- Support level
- Size
- Not measured
- Who uses it
- No live product imports it yet
import { DonutChart, PieChart } from "@krizaka/charts/pie";Web and mobile — the same component for React and React Native. Beta: its API may still change in a minor version.
Why it is here. Used by Sovkora.
When to use
- How one total splits at one moment: credits spent by model this month, storage by kind.
- Two to six parts, one of which clearly dominates or is clearly small.
When not to use
- Parts compared precisely, or more than six of them.Use instead: Bar chart
- Parts that change over time.Use instead: Area chart
- Nested parts (a team, then its projects).Use instead: Treemap
Installation
Install
npm install @krizaka/chartsImport
import { DonutChart, PieChart } from "@krizaka/charts/pie";Examples
Donut
This month's Sovkora credits by model, the total in the hole.
Pie
Storage by kind of file, the small kinds folded into “Other”.
Props
DonutChart
A pie with a hole: the total (or centerValue) and centerLabel in it.
| Prop | Type | Default | Description |
|---|---|---|---|
datarequired | readonly T[] | — | One row per part. |
labelrequired | string | ((datum: T, index: number) => string) | — | The field (or function) naming the part. |
valuerequired | string | ((datum: T, index: number) => number) | — | The field (or function) of its amount (≥ 0). |
actionsMenu | boolean | — | The ⋯ actions menu of the kit. false: the former “Show data” and export buttons, drawn in line. Default true. |
brand | BrandId | — | The brand whose palette the charts use. Without it, a chart follows a .brand-<id> ancestor, else Krizaka. Set it
when the app loads a brand stylesheet on :root (@krizaka/tokens/brands/sovkora.css). |
centerLabel | string | — | The words under the number in the hole of a donut (“Total credits”). |
centerValue | string | — | The number in the hole, written already. Default: the total. |
className | string | — | A class on the figure (layout: margins, grid placement). |
color | string | ((datum: T, index: number) => SeriesColor) | — | A part's own colour (a slot, a tone or a CSS colour); default: the palette in order of size. |
dataTable | boolean | — | “View as table” in the actions menu (the table is in the page for screen readers either way). Default true. |
description | ReactNode | — | A sentence under the title: the period, the unit, the source. |
empty | ReactNode | — | What to show when there is nothing to draw (default: the empty label). An EmptyState of
@krizaka /ui fits. |
error | ReactNode | — | The data could not be loaded: true says the default words, a node says yours (a retry button…). |
exportable | boolean | readonly ExportFormat[] | — | The downloads of the actions menu: all three by default, or the formats you want, or false for none. |
format | ValueFormat | — | How the amounts are written. |
height | number | — | The height of the plot in pixels. Default 280 (a sparkline: 32). |
hideTitle | boolean | — | Visually hide the title (it stays the chart's accessible name): a card that already has its heading. |
id | string | — | The id of the figure. |
insight | ReactNode | — | One line that says what the chart shows, between the title and the chart: “100 jobs · +100 % vs last week”. |
labelHeader | string | — | The header of the parts in the data table. |
labels | ChartLabelsInput | — | The words, translated: the buttons, the states, the written summary. |
live | boolean | — | Streaming data (a job queue, an auction): no entrance on updates, no announcement of every new point. |
loading | boolean | — | The data is on its way: a skeleton of the chart, announced once. |
locale | Locale | — | The locale of every figure and date ("fr-FR"). Default "en-US". |
maxSlices | number | — | At most this many slices; the rest fold into one, named otherLabel. Default 6. |
onSelect | ((datum: T, index: number) => void) | — | Called with the row when a slice is clicked (or Enter is pressed on it). |
otherLabel | string | — | The name of the folded slice. Default “Other”. |
style | CSSProperties | — | Inline style on the figure (layout only: colours come from the tokens). |
summary | "hidden" | "visible" | — | The written summary: read by screen readers only ("hidden", default), or shown under the chart ("visible"). |
summaryText | string | — | Your own summary instead of the generated one (still read first by screen readers). |
title | string | — | What the chart shows, in a few words: its accessible name, and its heading unless hideTitle. Inside a ChartCard, the card's title is the default. |
valueHeader | string | — | The header of the amounts in the data table. |
PieChart
| Prop | Type | Default | Description |
|---|---|---|---|
datarequired | readonly T[] | — | One row per part. |
labelrequired | string | ((datum: T, index: number) => string) | — | The field (or function) naming the part. |
valuerequired | string | ((datum: T, index: number) => number) | — | The field (or function) of its amount (≥ 0). |
actionsMenu | boolean | — | The ⋯ actions menu of the kit. false: the former “Show data” and export buttons, drawn in line. Default true. |
brand | BrandId | — | The brand whose palette the charts use. Without it, a chart follows a .brand-<id> ancestor, else Krizaka. Set it
when the app loads a brand stylesheet on :root (@krizaka/tokens/brands/sovkora.css). |
centerLabel | string | — | The words under the number in the hole of a donut (“Total credits”). |
centerValue | string | — | The number in the hole, written already. Default: the total. |
className | string | — | A class on the figure (layout: margins, grid placement). |
color | string | ((datum: T, index: number) => SeriesColor) | — | A part's own colour (a slot, a tone or a CSS colour); default: the palette in order of size. |
dataTable | boolean | — | “View as table” in the actions menu (the table is in the page for screen readers either way). Default true. |
description | ReactNode | — | A sentence under the title: the period, the unit, the source. |
donut | boolean | — | A ring rather than a pie: the total (or centerValue) is written in its hole. |
empty | ReactNode | — | What to show when there is nothing to draw (default: the empty label). An EmptyState of
@krizaka /ui fits. |
error | ReactNode | — | The data could not be loaded: true says the default words, a node says yours (a retry button…). |
exportable | boolean | readonly ExportFormat[] | — | The downloads of the actions menu: all three by default, or the formats you want, or false for none. |
format | ValueFormat | — | How the amounts are written. |
height | number | — | The height of the plot in pixels. Default 280 (a sparkline: 32). |
hideTitle | boolean | — | Visually hide the title (it stays the chart's accessible name): a card that already has its heading. |
id | string | — | The id of the figure. |
insight | ReactNode | — | One line that says what the chart shows, between the title and the chart: “100 jobs · +100 % vs last week”. |
labelHeader | string | — | The header of the parts in the data table. |
labels | ChartLabelsInput | — | The words, translated: the buttons, the states, the written summary. |
live | boolean | — | Streaming data (a job queue, an auction): no entrance on updates, no announcement of every new point. |
loading | boolean | — | The data is on its way: a skeleton of the chart, announced once. |
locale | Locale | — | The locale of every figure and date ("fr-FR"). Default "en-US". |
maxSlices | number | — | At most this many slices; the rest fold into one, named otherLabel. Default 6. |
onSelect | ((datum: T, index: number) => void) | — | Called with the row when a slice is clicked (or Enter is pressed on it). |
otherLabel | string | — | The name of the folded slice. Default “Other”. |
style | CSSProperties | — | Inline style on the figure (layout only: colours come from the tokens). |
summary | "hidden" | "visible" | — | The written summary: read by screen readers only ("hidden", default), or shown under the chart ("visible"). |
summaryText | string | — | Your own summary instead of the generated one (still read first by screen readers). |
title | string | — | What the chart shows, in a few words: its accessible name, and its heading unless hideTitle. Inside a ChartCard, the card's title is the default. |
valueHeader | string | — | The header of the amounts in the data table. |
Accessibility
- The plot is a group named by the title and described by a summary written from the data, read before anything else.
- The data table is always in the page for assistive technology; “Show data” reveals it for everyone.
- Colour never carries a meaning alone: the legend, the labels and the table say it in words.
- The entrance plays once, when the chart comes on screen, and never under reduced motion.
- A 2 px gap in the surface colour separates the slices.
Keyboard
| Keys | Action |
|---|---|
| Tab | Moves the focus to the plot (one tab stop), then to the data and export buttons. |
| Arrow keys | Walk the items one by one: each is announced and its tooltip shown. |
| Home / End | Jump to the first or the last item. |
| Esc | Hides the tooltip and clears the active item. |
| Enter | Selects the active slice (calls onSelect with its row). |
Best practices
- Prefer the donut (
DonutChart) withcenterLabel: the total is the first thing a reader looks for. - Name the folded slice in your language with
otherLabel. - Never put two pies side by side to compare them: use bars.
Related components
Generated from the code of @krizaka/ui 5.3.4: its meta.ts, its examples and its types.Edit this documentation on GitHub