PieChart
PieChart shows how category values contribute to a whole. It renders a doughnut, assigns each category a chart-series color, separates slices with a 1px background-revealing gap, and identifies slices through its keyboard-accessible tooltip.
import { PieChart } from "density-base-ui";
const trafficSources = [
{ label: "Direct", value: 42 },
{ label: "Search", value: 31 },
{ label: "Referral", value: 17 },
{ label: "Email", value: 10 },
];
export default function PieChartExample() {
return <PieChart aria-label="Traffic sources" data={trafficSources} />;
}data and aria-label are required. PieChart cycles through chart-series colors for every pie. size controls the title size, while emphasis controls its color.
Spark
Set spark for a compact 16px chart without visible labels or outer padding. Spark charts still expose their data through keyboard-accessible tooltips.
import { PieChart, View } from "density-base-ui";
const incidentSources = [
{ label: "Monitor", value: 46 },
{ label: "User", value: 24 },
{ label: "Deploy", value: 18 },
{ label: "Vendor", value: 12 },
];
export default function PieChartSparkExample() {
return (
<View align="start" gap="md" padding={false}>
<PieChart
aria-label="Incident source share"
data={incidentSources}
spark
style={{ width: "160px" }}
/>
</View>
);
}Emphasis
import { PieChart, View } from "density-base-ui";
const data = [
{ label: "Direct", value: 60 },
{ label: "Search", value: 40 },
];
export default function PieChartEmphasisExample() {
return (
<View
gap="xl"
layout="grid"
padding={false}
style={{
gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
width: "100%",
}}
>
<PieChart
aria-label="Primary"
data={data}
emphasis="primary"
height={120}
title="Primary"
/>
<PieChart
aria-label="Secondary"
data={data}
emphasis="secondary"
height={120}
title="Secondary"
/>
<PieChart
aria-label="Outline"
data={data}
emphasis="outline"
height={120}
title="Outline"
/>
<PieChart
aria-label="Ghost"
data={data}
emphasis="ghost-primary"
height={120}
title="Ghost"
/>
</View>
);
}Size
import { PieChart, View } from "density-base-ui";
const data = [
{ label: "Direct", value: 60 },
{ label: "Search", value: 40 },
];
export default function PieChartSizeExample() {
return (
<View
gap="xl"
layout="grid"
padding={false}
style={{
gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
width: "100%",
}}
>
<PieChart
aria-label="2xs"
data={data}
height={100}
size="2xs"
title="2xs"
/>
<PieChart aria-label="xs" data={data} height={100} size="xs" title="xs" />
<PieChart aria-label="sm" data={data} height={100} size="sm" title="sm" />
<PieChart aria-label="md" data={data} height={100} size="md" title="md" />
<PieChart aria-label="lg" data={data} height={100} size="lg" title="lg" />
<PieChart aria-label="xl" data={data} height={100} size="xl" title="xl" />
<PieChart
aria-label="2xl"
data={data}
height={100}
size="2xl"
title="2xl"
/>
<PieChart
aria-label="3xl"
data={data}
height={100}
size="3xl"
title="3xl"
/>
</View>
);
}Title
import { PieChart } from "density-base-ui";
const data = [
{ label: "Direct", value: 60 },
{ label: "Search", value: 40 },
];
export default function PieChartTitleExample() {
return (
<PieChart
aria-label="Traffic sources"
data={data}
title="Traffic sources"
subtitle="Visitors from the previous seven days"
/>
);
}Height
import { PieChart, View } from "density-base-ui";
const data = [
{ label: "Direct", value: 60 },
{ label: "Search", value: 40 },
];
export default function PieChartHeightExample() {
return (
<View
gap="xl"
layout="grid"
padding={false}
style={{
gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
width: "100%",
}}
>
<PieChart
aria-label="120 pixel chart"
data={data}
height={120}
title="120 pixels"
/>
<PieChart
aria-label="240 pixel chart"
data={data}
height={240}
title="240 pixels"
/>
</View>
);
}Padding
Set padding to add outer spacing around a standard chart frame without changing the plotted slices’ geometry. Spark charts ignore padding.
import { PieChart } from "density-base-ui";
const trafficSources = [
{ label: "Organic", value: 42 },
{ label: "Referral", value: 27 },
{ label: "Direct", value: 18 },
{ label: "Paid", value: 13 },
];
export default function PieChartPaddingExample() {
return (
<PieChart
aria-label="Traffic sources with padding"
data={trafficSources}
padding
/>
);
}| Prop | Values | Required | Default | Behavior | Description |
|---|---|---|---|---|---|
childrenEnd | React.ReactNode | Not required | — | — | — |
childrenStart | React.ReactNode | Not required | — | — | — |
data | import("density-base-ui/src/index").ValueChartDatum[] | Required | — | — | — |
emphasis | primary, secondary, outline, ghost-primary | Not required | — | — | Controls the Density label color used by visible chart annotations. |
height | number | Not required | — | — | — |
padding | false, true | Not required | — | — | Outer spacing around the frame; does not affect plotted mark geometry. |
size | 2xs, xs, sm, md, lg, xl, 2xl, 3xl | Not required | — | — | Controls the Density label size used by visible chart annotations. |
spark | false, true | Not required | false | — | — |
subtitle | React.ReactNode | Not required | — | — | — |
title | React.ReactNode | Not required | — | — | — |
This component also accepts props from native APIs. They are passed through and intentionally kept out of this focused Density API table.