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