Aller au contenu principal

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​

Ouvrir Simple dans Storybook

With Explicit Patterns​

Ouvrir With Patterns dans Storybook

Without Legend​

Ouvrir No Legend dans Storybook

Small Size​

Ouvrir Small Size dans Storybook

Legend Beside a Wide Pie​

Ouvrir Wide With Legend Right dans Storybook

See Also​