"use client";
import {
ChartcnPieChart,
Pie,
Tooltip,
Legend,
} from "@/components/charts/pie-chart";
import type { ChartConfig } from "@/components/ui/chart";
const data = [
{ browser: "chrome", visitors: 275 },
{ browser: "safari", visitors: 200 },
{ browser: "firefox", visitors: 187 },
{ browser: "edge", visitors: 173 },
{ browser: "other", visitors: 90 },
];
const chartConfig = {
chrome: {
colors: {
dark: ["#60a5fa"],
light: ["#3b82f6"],
},
label: "Chrome",
},
edge: {
colors: {
dark: ["#a78bfa"],
light: ["#8b5cf6"],
},
label: "Edge",
},
firefox: {
colors: {
dark: ["#fbbf24"],
light: ["#f59e0b"],
},
label: "Firefox",
},
other: {
colors: {
dark: ["#9ca3af"],
light: ["#6b7280"],
},
label: "Other",
},
safari: {
colors: {
dark: ["#34d399"],
light: ["#10b981"],
},
label: "Safari",
},
} satisfies ChartConfig;
export function ChartcnExamplePieChart() {
return (
<ChartcnPieChart
className="h-full w-full p-4"
data={data}
dataKey="visitors"
nameKey="browser"
config={chartConfig}
>
<Legend isClickable />
<Tooltip />
<Pie isClickable />
</ChartcnPieChart>
);
}Install
$ pnpm dlx shadcn@latest add @chartcn/pie-chart
Configure donut radius, slice padding, rounded corners, labels, selection, and per-category theme palettes through the declarative chart API.