
A donut where one slice is enlarged and outlined with an outer arc to highlight it.
@esuiss
components/charts/pie-chart-active.tsx
"use client"
import { Pie, PieChart, Sector } from "recharts"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
type ChartConfig,
ChartContainer,
ChartTooltip,
ChartTooltipContent,
} from "@/components/ui/chart"
const chartData = [
{ device: "phone", users: 275, fill: "var(--color-phone)" },
{ device: "laptop", users: 200, fill: "var(--color-laptop)" },
{ device: "tablet", users: 187, fill: "var(--color-tablet)" },
{ device: "watch", users: 173, fill: "var(--color-watch)" },
{ device: "other", users: 90, fill: "var(--color-other)" },
]
const chartConfig = {
users: { label: "Users" },
phone: { label: "Phone", color: "var(--chart-1)" },
laptop: { label: "Laptop", color: "var(--chart-2)" },
tablet: { label: "Tablet", color: "var(--chart-3)" },
watch: { label: "Watch", color: "var(--chart-4)" },
other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig
const ACTIVE = 0
export function PieChartActive() {
return (
<Card variant="filled" size="sm">
<CardHeader>
<CardTitle>Highlighted slice</CardTitle>
<CardDescription>The selected slice pops out</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer
config={chartConfig}
className="aspect-auto h-52 w-full"
>
<PieChart accessibilityLayer>
<ChartTooltip
cursor={false}
content={<ChartTooltipContent hideLabel nameKey="device" />}
/>
<Pie
data={chartData}
dataKey="users"
nameKey="device"
innerRadius="50%"
outerRadius="78%"
strokeWidth={0}
shape={(props, index) =>
index === ACTIVE ? (
<g>
<Sector
{...props}
outerRadius={(props.outerRadius ?? 0) + 10}
/>
<Sector
{...props}
innerRadius={(props.outerRadius ?? 0) + 13}
outerRadius={(props.outerRadius ?? 0) + 16}
/>
</g>
) : (
<Sector {...props} />
)
}
/>
</PieChart>
</ChartContainer>
</CardContent>
</Card>
)
}





























