DonutChart
Each datum has a label, value, and color. Children render in the centre.
Donut chart, 4 points. Values from 8 to 42.
Show data table
| Category | Value | Percentage |
|---|---|---|
| Pass | 42 | 49% |
| Fail | 8 | 9% |
| N/A | 12 | 14% |
| To do | 24 | 28% |
import { DonutChart } from '@eekodigital/raster';
<DonutChart
data={[
{ label: 'Pass', value: 42, color: 'var(--demo-good)' },
{ label: 'Fail', value: 8, color: 'var(--demo-bad)' },
{ label: 'N/A', value: 12, color: 'var(--demo-neutral)' },
{ label: 'To do', value: 24, color: 'var(--demo-warn)' },
]}
title="Conformance summary"
>
<strong>86</strong>
<span>criteria</span>
</DonutChart>Small / progress indicator
Section titled “Small / progress indicator”Use smaller size and thickness for inline progress indicators.
Donut chart, 2 points. Values from 25 to 75.
Show data table
| Category | Value | Percentage |
|---|---|---|
| Complete | 75 | 75% |
| Remaining | 25 | 25% |
<DonutChart
data={[
{ label: 'Complete', value: 75, color: 'var(--demo-good)' },
{ label: 'Remaining', value: 25, color: 'var(--demo-muted)' },
]}
size={80}
thickness={10}
title="75% complete"
>
<strong>75%</strong>
</DonutChart>Accessibility
Section titled “Accessibility”- A
role="figure"named by the visibletitleand described by a generated summary (chart type, series and point counts, range). - The SVG is a
role="group"witharia-roledescription="chart"; nographics-*roles. - Each segment is labelled
{label}: {value} ({percent}), 2 of 4. Zero-value segments are skipped. WithonSelect,selectedIndexor a click handler, marks arerole="button"witharia-pressed; otherwise they’re staticrole="img". - A visible Show data table disclosure (a native
<details>/<summary>, so it opens without JavaScript) reveals a real table captionedData for {title}, withth scopeheaders and values run throughformatValue. - Escape (inside the chart only) clears the selection and announces it in a polite live region; it doesn’t close a surrounding dialog.
- The draw-in animation is a CSS class, so
prefers-reduced-motionswitches it off. - Animations stop under
prefers-reduced-motion. In forced-colours mode marks use system colours, told apart by dash pattern and marker shape.
| Key | Action |
|---|---|
| ← → ↑ ↓ | Previous / next segment (wraps) |
| Home / End | First / last segment |
| Tab | Leave the chart |
| Enter / Space | Toggle selection (interactive marks) |
| Escape | Hide the tooltip and clear selection |
See the Accessibility guide for the shared structure, the labels prop and screen-reader testing.
| Prop | Type | Description |
|---|---|---|
data | DonutDatum[] | Required. |
size | number | Fixed diameter in px. Omit to fill the container’s width (square). |
thickness | numberDefault: | Ring thickness in px. |
children | ReactNode | Centre content. |
showLegend | booleanDefault: | Show a legend. |
formatValue | (value: number) => stringDefault: | Formats values in ticks, marks and the table. Defaults to |
onMarkClick | (mark: { index: number, value, datum: DonutDatum }) => void | Called when a mark is clicked (or activated with Enter/Space) with
|
selectedIndex | number | null | Controlled selection. |
onSelect | (index | null) => void | Makes segments buttons. |
title | string | Required. Visible title: names the figure and captions the data table. |
hideTitle | booleanDefault: | Hide the title visually. It still names the chart for assistive technology. |
labels | ChartLabelOverridesDefault: English | Generated strings and the number locale. See Accessibility. |
dataTable | “disclosure” | “visually-hidden” | “none”Default: | How the data table is offered: behind a Show data table button, for screen readers only, or not at all, when you offer the data yourself. See Accessibility. |
actions | ReactNode | Shown on the same row as the Show data table button, such as download buttons. |
ref | Ref<HTMLDivElement> | The chart’s root element, e.g. for |
className | string | Class on the figure. |