Skip to content
ChartslibraryUI Get Pro

Pie chart

Two to five parts of one whole, with a value-and-share legend.

FreeMIT · install in one command<PieChart />

When to use

  • Two to five parts of a single whole
  • When the audience expects a pie

When not to use

Good practice

  • Prefer a bar chart when values are close, because angles are hard to compare.
  • Never use 3D or exploded slices.

Installation

Pie chart is free under the MIT license.

$ npx shadcn@latest add https://chartslibraryui.com/r/pie-chart.json

Installs 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

Usage

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"
    />
  );
}

Data

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

Props

Every chart also accepts the shared frame props: title, subtitle, source, height, mode, toolbar. Common API

// See PieChart in the source

Source

Installs pie-chart.tsx and the shared core/ (11 files).

View pie-chart.tsx
"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} />;
}

Donut chart

One whole in up to six parts, with the total in the middle and a value legend.

Waffle chart

A countable part-to-whole: one square is one percent.