Donut Chart
boldkit/donut-chartFreeComponent
Pie chart with center hole for KPI display, supports center content slot
Live preview
live · rendered by the registry
Rendered by boldkit on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://boldkit.dev/r/donut-chart.jsonSource
1import * as React from 'react'2import { cn } from '@/lib/utils'3import { Pie, PieChart, Cell, Label } from 'recharts'4import { ChartContainer } from './chart'5import { ChartEmpty } from './chart'6import { ChartTooltip, ChartTooltipContent } from './chart'7import type { ChartConfig } from './chart'89export interface DonutChartData {10 name: string11 value: number12 fill?: string13}1415export interface DonutChartProps extends React.HTMLAttributes<HTMLDivElement> {16 data: DonutChartData[]17 config: ChartConfig18 innerRadius?: string | number19 outerRadius?: string | number20 centerContent?: React.ReactNode21 showLabels?: 'none' | 'inside' | 'outside'22 variant?: 'default' | 'separated'23 showTooltip?: boolean24 animated?: boolean25 emptyState?: React.ReactNode26}2728const DonutChart = React.forwardRef<HTMLDivElement, DonutChartProps>(29 (30 {31 data,32 config,33 innerRadius = '60%',34 outerRadius = '80%',35 centerContent,36 showLabels = 'none',37 variant = 'default',38 showTooltip = true,39 animated = true,40 emptyState,41 className,42 ...props43 },44 ref45 ) => {46 if (!data || data.length === 0) {47 return <ChartEmpty ref={ref} message={emptyState} className={className} {...props} />48 }4950 const paddingAngle = variant === 'separated' ? 4 : 05152 return (53 <ChartContainer54 ref={ref}55 config={config}56 className={cn('aspect-square max-h-[300px]', className)}57 {...props}58 >59 <PieChart>60 {showTooltip && (61 <ChartTooltip62 cursor={false}63 content={<ChartTooltipContent hideLabel />}64 />65 )}66 <Pie67 data={data}68 dataKey="value"69 nameKey="name"70 cx="50%"71 cy="50%"72 innerRadius={innerRadius}73 outerRadius={outerRadius}74 paddingAngle={paddingAngle}75 strokeWidth={3}76 stroke="hsl(var(--foreground))"77 isAnimationActive={animated}78 animationDuration={400}79 label={80 showLabels === 'outside'81 ? ({ name, percent }: { name?: string; percent?: number }) => `${name ?? ''}: ${((percent ?? 0) * 100).toFixed(0)}%`82 : showLabels === 'inside'83 ? ({ percent }: { percent?: number }) => `${((percent ?? 0) * 100).toFixed(0)}%`84 : false85 }86 labelLine={showLabels === 'outside'}87// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from boldkit
All 94 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | boldkit | Components | Free | 2 deps | |
| Alertalert | boldkit | Components | Free | 2 deps | |
| Alert Dialogalert-dialog | boldkit | Components | Free | 1 dep | |
| ASCII Shapesascii-shapes | boldkit | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | boldkit | Components | Free | 1 dep | |
| Avataravatar | boldkit | Components | Free | 1 dep | |
| Badgebadge | boldkit | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | boldkit | Components | Free | 2 deps |
