Charts
PieChart
Parts of a whole, for up to six parts. The legend and the table give each part’s share, so readers do not have to judge angles.
import '@reactloom/charts/styles.css';
import { PieChart } from '@reactloom/charts';Examples
Donut with a total
- Enterprise47.6%
- Team31.3%
- Starter15.3%
- Trial5.9%
seats
import { PieChart } from '@reactloom/charts';
const seats = [
{ plan: 'Enterprise', seats: 1284 },
{ plan: 'Team', seats: 846 },
{ plan: 'Starter', seats: 412 },
{ plan: 'Trial', seats: 158 },
];
export default function Example() {
return (
<div style={{ width: '100%', maxWidth: 420 }}>
<PieChart
title="Seats by plan"
data={seats}
label="plan"
value="seats"
donut
centerLabel={
<>
2,700
<br />
seats
</>
}
/>
</div>
);
}Pie
- Email51.1%
- Chat37%
- Phone11.9%
import { PieChart } from '@reactloom/charts';
const tickets = [
{ channel: 'Email', count: 412 },
{ channel: 'Chat', count: 298 },
{ channel: 'Phone', count: 96 },
];
export default function Example() {
return (
<div style={{ width: '100%', maxWidth: 360 }}>
<PieChart title="Support tickets by channel, October" data={tickets} label="channel" value="count" height={220} />
</div>
);
}API reference
| Prop | Type | Default |
|---|---|---|
titlerequired | string | — |
datarequired | Row[] | — |
labelrequiredName of each slice. | key | (row) => string | — |
valuerequiredSize of each slice (negative values count as zero). | key | (row) => number | — |
donutDraw a ring. | boolean | — |
centerLabelShown inside a donut, e.g. the total. | ReactNode | — |
colorDefaults to the theme palette. | (row, index) => string | — |
legend | boolean | true |
description · valueFormat · table · heightAs the other charts. | | — |
Customization
Series colours are the theme tokens --pl-color-chart-1 to --pl-color-chart-6, used in order. Set them in a theme (createTheme({ colors: { 'chart-1': '#0E7C66' } }), contrast-checked by checkThemeContrast) or per series with color.
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-active] | present when on |
[data-series] | present when on |
Theme tokens it reads
--pl-color-bg-surface --pl-color-border-default --pl-color-fg-muted --pl-focus-ring-color --pl-focus-ring-offset --pl-focus-ring-width --pl-font-size-sm --pl-radius-md --pl-radius-sm --pl-radius-xs
Accessibility
- Each chart is a
<figure>named by its title and described by a summary. Write thedescriptionyourself to state the takeaway; otherwise a factual summary is generated from the data (range, lowest and highest values, change from first to last), formatted for the active locale. - The drawing is hidden from assistive technology. Screen-reader users get the summary and the data table (“Show data table”), which is a real, sortable table.
- The plot is one tab stop. Arrow keys move between data points, a visible tooltip follows, and a polite live region reads the values. It is not
role="application", so screen readers keep their normal reading keys; in browse mode, use the table. - Colours come from the theme’s chart palette, each at least 3:1 against the background in every built-in theme. In Windows high-contrast mode series switch to system colours with dash patterns.
- In right-to-left layouts the x axis runs from the right and the value axis moves to the right side; ← moves forward.
| Key | Action |
|---|---|
| Tab | Focus the chart |
| → / ↓ | Next slice (wraps) |
| ← / ↑ | Previous slice (wraps) |
| Home / End | First / last slice |
| Escape | Hide the tooltip |
Usage guidelines
Do
- Use it when the share of the whole is the point.
- Show the total in the centre of a donut.
Don’t
- Don’t use it for more than six parts or to compare similar sizes — use a BarChart.
- Don’t use it for values that don’t add up to a whole.