Donut chart
One whole in up to six parts, with the total in the middle and a value legend.
Two to five parts of one whole, with a value-and-share legend.
<PieChart />Pie chart is free under the MIT license.
$ npx shadcn@latest add https://chartslibraryui.com/r/pie-chart.jsonInstalls the chart, its dependencies and the shared core into your components folder.
Then import the theme once: import "@/components/charts/core/charts.css" Installation guide
import { PieChart } from "@/components/charts/pie-chart";
import { customersByPlan } from "./sample-data";
export function Example() {
return (
<PieChart
title="Half of customers are on Starter"
subtitle="Customers by plan"
data={customersByPlan}
label="plan"
value="customers"
format="integer"
/>
);
}
Rows with a label key and a non-negative value key.
[{ plan: "Team", customers: 820 }, ...]Missing values are null. Invalid values make the chart say what’s wrong instead of drawing a misleading picture. How charts handle bad data
Every chart also accepts the shared frame props: title, subtitle, source, height, mode, toolbar. Common API
// See PieChart in the sourceInstalls pie-chart.tsx and the shared core/ (11 files).
"use client";
import { DonutChart, type DonutChartProps } from "./donut-chart";
export type PieChartProps = Omit<DonutChartProps, "innerRadius" | "centerLabel" | "centerCaption">;
/**
* Two to five parts of one whole. If readers need to compare parts precisely, or there are more than five, use a
* horizontal bar chart: angles are harder to compare than lengths.
*/
export function PieChart({ maxSlices = 5, ...props }: PieChartProps) {
return <DonutChart {...props} maxSlices={maxSlices} innerRadius={0} centerLabel={null} />;
}
One whole in up to six parts, with the total in the middle and a value legend.
A countable part-to-whole: one square is one percent.