c-chart-20.tsx
"use client"
import { CSSProperties } from "react"
import { Label, Pie, PieChart } from "recharts"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
ChartContainer,
ChartLegend,
ChartLegendContent,
ChartTooltip,
ChartTooltipContent,
type ChartConfig,
} from "@/components/ui/chart"
const chartData = [
{ status: "completed", count: 186, fill: "var(--color-completed)" },
{ status: "inProgress", count: 94, fill: "var(--color-inProgress)" },
{ status: "pending", count: 62, fill: "var(--color-pending)" },
{ status: "cancelled", count: 28, fill: "var(--color-cancelled)" },
]
const totalTasks = chartData.reduce((sum, d) => sum + d.count, 0)
const completionRate = Math.round((chartData[0].count / totalTasks) * 100)
const chartConfig = {
count: { label: "Tasks" },
completed: { label: "Completed", color: "var(--chart-1)" },
inProgress: { label: "In Progress", color: "var(--chart-2)" },
pending: { label: "Pending", color: "var(--chart-3)" },
cancelled: { label: "Cancelled", color: "var(--chart-5)" },
} satisfies ChartConfig
export function Pattern() {
return (
<Card className="w-full max-w-xs">
<CardHeader className="items-center pb-0">
<CardTitle>Task Status</CardTitle>
<CardDescription>Current sprint task breakdown</CardDescription>
</CardHeader>
<CardContent className="flex-1 pb-0">
<ChartContainer
config={chartConfig}
className="mx-auto aspect-square max-h-[280px]"
>
<PieChart accessibilityLayer>
<ChartTooltip
content={
<ChartTooltipContent
className="min-w-40 gap-2.5"
formatter={(value, name) => (
<div className="flex w-full items-center justify-between gap-2">
<div className="flex items-center gap-1.5">
<div
className="h-2.5 w-2.5 shrink-0 rounded-xs bg-(--color-bg)"
style={
{
"--color-bg": `var(--color-${name})`,
} as CSSProperties
}
/>
<span className="text-muted-foreground">
{chartConfig[name as keyof typeof chartConfig]
?.label || name}
</span>
</div>
<span className="text-foreground font-semibold tabular-nums">
{Number(value).toLocaleString()}
</span>
</div>
)}
/>
}
/>
<ChartLegend
content={<ChartLegendContent nameKey="status" />}
className="-translate-y-2"
/>
<Pie
data={chartData}
dataKey="count"
nameKey="status"
innerRadius={60}
cornerRadius={5}
paddingAngle={3}
stroke="var(--background)"
strokeWidth={3}
>
<Label
content={({ viewBox }) => {
if (viewBox && "cx" in viewBox && "cy" in viewBox) {
return (
<text
x={viewBox.cx}
y={viewBox.cy}
textAnchor="middle"
dominantBaseline="middle"
>
<tspan
x={viewBox.cx}
y={viewBox.cy}
className="fill-foreground text-3xl font-bold tabular-nums"
>
{completionRate}%
</tspan>
<tspan
x={viewBox.cx}
y={(viewBox.cy || 0) + 22}
className="fill-muted-foreground text-xs"
>
Completed
</tspan>
</text>
)
}
}}
/>
</Pie>
</PieChart>
</ChartContainer>
</CardContent>
</Card>
)
}





























