# Pie Chart

> Solid sector pie proportions chart displaying category share breakdown.

A shadcn/ui block from the [@pacekit](https://ui.pacekit.dev/?utm_source=shadcn.exchange) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/pacekit/tanstack-charts-pie-chart).

- Page, with a live preview: https://shadcn.exchange/r/pacekit/tanstack-charts-pie-chart
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/pacekit/tanstack-charts-pie-chart-light-d75020fb403b4101.png
- Registry item: https://ui.pacekit.dev/r/tanstack-charts-pie-chart.json
- Listed: 2026-10-21, source last changed 2026-10-21

## Install

```bash
npx shadcn@latest add https://shadcn.exchange/r/pacekit/tanstack-charts-pie-chart.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `@tanstack/charts`, `@tanstack/react-charts`
- Registry items: `card`

## Files

### `components/tanstack-charts/pie/pie-chart.tsx`

```tsx
import { type ChartPoint, defineChart } from "@tanstack/charts";
import { motion } from "@tanstack/charts/motion";
import { pie, polar, radialArc } from "@tanstack/charts/polar";
import { tooltip } from "@tanstack/charts/tooltip";
import { Chart } from "@tanstack/react-charts/core";
import { useMemo } from "react";

import { PieChartIcon } from "lucide-react";

import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";

interface BrowserDatum {
    browser: string;
    share: number;
}

const motionRenderer = motion({
    initial: "always",
    transition: { type: "spring", stiffness: 170, damping: 18, mass: 1 },
});

function generateDemoData(): BrowserDatum[] {
    return [
        { browser: "Chrome", share: 0.64 },
        { browser: "Safari", share: 0.19 },
        { browser: "Edge", share: 0.08 },
        { browser: "Firefox", share: 0.06 },
        { browser: "Others", share: 0.03 },
    ];
}

function shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {
    if (points.length === 0) return { title: "", rows: [] };
    const d = points[0].datum as BrowserDatum;
    if (!d) return { title: "", rows: [] };
    return {
        title: d.browser,
        rows: [{ label: "Market Share", value: `${(d.share * 100).toFixed(1)}%`, color: "var(--chart-1)" }],
    };
}

export function PieChart() {
    const data = useMemo(() => generateDemoData(), []);

    const arcs = useMemo(() => {
        return pie(data, {
            value: "share",
        });
    }, [data]);

    const definition = useMemo(
        () =>
            defineChart(
                {
                    renderer: motionRenderer,
                    scales: {
                        x: null,
                        y: null,
                    },
                    marks: [
                        polar({
                            inset: 0,
                            radiusRatio: 0.8,
                            scales: {
                                angle: null,
                                radius: null,
                            },
                            marks: [
                                radialArc(arcs, {
                                    id: "browser-slices",
                                    key: "browser",
                                    color: "browser",
                                    stroke: "var(--background)",
                                    strokeWidth: 2,
                                }),
                            ],
                        }),
                    ],
                    color: {
                        range: [
                            "var(--chart-1)",
                            "var(--chart-2)",
                            "var(--chart-3)",
                            "var(--chart-4)",
                            "var(--chart-5)",
                        ],
                    },
                    margin: 10,
                    theme: {
                        foreground: "var(--muted-foreground)",
                        grid: "var(--border)",
                        background: "transparent",
                    },
                },
                {
                    keyboard: true,
                    tooltip: {
                        use: tooltip,
                        className:
                            "font-sans shadow-none rounded-md bg-popover text-popover-foreground border p-2 text-xs",
                        anchor: "pointer",
                        placement: "auto",
                        content: (points) => shadcnTooltipContent(points),
                    },
                },
            ),
        [arcs],
    );

    return (
        <Card className="w-full max-w-xl">
            <CardHeader>
                <CardTitle>Solid Sector Pie Proportions Chart</CardTitle>
                <CardDescription>
                    Full circular pie slices representing relative categorical percentage shares
                </CardDescription>
            </CardHeader>
            <CardContent>
                <div className="flex h-[250px] w-full items-center justify-center">
                    <Chart
                        definition={definition}
                        renderer={motionRenderer}
                        height={250}
                        ariaLabel="Solid Sector Pie Proportions Chart"
                    />
                </div>
            </CardContent>
            <CardFooter className="flex-col items-start gap-2 text-sm">
                <div className="flex items-center gap-2 leading-none font-medium">
                    Chrome retains majority 64% global web market share{" "}
                    <PieChartIcon className="h-4 w-4 text-emerald-500" />
                </div>
                <div className="text-muted-foreground leading-none">
                    Radial arc transformation converts proportional scalar values into 360-degree pie segments
                </div>
            </CardFooter>
        </Card>
    );
}

export default PieChart;
```
