Skip to main content

PieChart

Every example on this page is live, drawn by the library's Storybook, where you can also change its props and see the result.

Slices of a whole, each filled with a pattern, with a legend naming every slice and its share.

The pie stays round in any box: it is drawn as large as the box holds and centered, in the widget and in its previews alike. The legend sits around it and wraps or stacks to fit the room left. Negative values take no share of the pie, and a chart with no value above zero draws nothing.

Import​

import { PieChart } from "~lib/charts/pie-chart";

Props​

NameTypeRequiredDefaultDescription
data{ label: string; value: number; pattern?: PatternType }[]YesN/ASlice data
showLegendbooleanNotrueShow a legend naming each slice and its share
legendPosition"bottom" | "right" | "top" | "left"No"bottom"Where the legend sits around the pie
widthnumber | stringNo300Chart width
heightnumber | stringNo300Chart height

PatternType: "solid" | "diagonal" | "dots" | "crosshatch" — patterns cycle automatically if not specified.

Examples​

Simple​

Open Simple in Storybook

With Explicit Patterns​

Open With Patterns in Storybook

Without Legend​

Open No Legend in Storybook

Small Size​

Open Small Size in Storybook

Legend Beside a Wide Pie​

Open Wide With Legend Right in Storybook

See Also​