Examples

Donut with a total

Preview
Seats by planDonut chart of 4 parts, total 2,700. Enterprise: 1,284 (47.6%); Team: 846 (31.3%); Starter: 412 (15.3%).
  • Enterprise47.6%
  • Team31.3%
  • Starter15.3%
  • Trial5.9%
Use the arrow keys to move between data points, Home and End to jump to the first and last.
2,700
seats
Example.tsx
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

Preview
Support tickets by channel, OctoberPie chart of 3 parts, total 806. Email: 412 (51.1%); Chat: 298 (37%); Phone: 96 (11.9%).
  • Email51.1%
  • Chat37%
  • Phone11.9%
Use the arrow keys to move between data points, Home and End to jump to the first and last.
Example.tsx
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

PieChart props
PropTypeDefault
titlerequired
string—
datarequired
Row[]—
labelrequired
Name of each slice.
key | (row) => string—
valuerequired
Size of each slice (negative values count as zero).
key | (row) => number—
donut
Draw a ring.
boolean—
centerLabel
Shown inside a donut, e.g. the total.
ReactNode—
color
Defaults to the theme palette.
(row, index) => string—
legend
booleantrue
description · valueFormat · table · height
As 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.

AttributeValues
[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 the description yourself 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.
Keyboard interactions
KeyAction
TabFocus the chart
→ / ↓Next slice (wraps)
← / ↑Previous slice (wraps)
Home / EndFirst / last slice
EscapeHide 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.