Getting Started
Charts
- Charts
- Line Chart
- Bar Chart
- Area Chart
- Scatter Chart
- Pie Chart
- Donut Chart
- Dot Plot Chart
- Lollipop Chart
- Dumbbell Chart
- Slope Chart
- Range Chart
- Histogram Chart
- Box Plot Chart
- Violin Chart
- Polar Chart
- Parallel Coordinates
- SPLOM Chart
- Parcats Chart
- Candlestick Chart
- OHLC Chart
- Waterfall Chart
- Funnel Chart
- Heatmap Chart
- Contour Chart
- Density Chart
- Ternary Chart
- Radar Chart
- Treemap Chart
- Sunburst Chart
- Sankey Chart
- Gauge Chart
- Bullet Chart
- Icicle Chart
- Network Graph
- Dendrogram
- Choropleth Chart
"use client"
import { DonutChart } from "@/components/ui/charts"
const data = [
{ label: "Chrome", value: 62.5, color: "#2563eb" },
{ label: "Safari", value: 19.3, color: "#3b82f6" },
{ label: "Firefox", value: 4.2, color: "#60a5fa" },
{ label: "Edge", value: 4.1, color: "#93c5fd" },
{ label: "Other", value: 9.9, color: "#bfdbfe" },
]
export function DonutChartDemo() {
return (
<div className="w-full max-w-md">
<DonutChart data={data} innerRadius={0.65} showLabels showTotal animate />
</div>
)
}
About
The Donut Chart displays data as proportional segments in a ring, with a hollow center for key metrics. Features smooth animations, interactive hover states, and multiple style variants.
Features:
- Animated entrance - Smooth animation on mount
- Interactive segments - Hover to highlight and see details
- Proper tooltips - Detailed tooltips following cursor
- Center content - Display totals or selected segment info
- Multiple variants - Default, gradient, and separated styles
- Label lines - Auto-positioned labels for small segments
Installation
pnpm dlx shadcn@latest add https://ui.simplifying.ai/r/donut-chart.json
Usage
import { DonutChart } from "@/components/ui/charts"
const data = [
{ label: "Chrome", value: 62.5, color: "#4285F4" },
{ label: "Safari", value: 19.3, color: "#FF9500" },
{ label: "Firefox", value: 4.2, color: "#FF7139" },
{ label: "Edge", value: 4.1, color: "#0078D7" },
{ label: "Other", value: 9.9, color: "#6B7280" },
]
export function Example() {
return <DonutChart data={data} innerRadius={0.65} showLabels animate />
}Variants
Gradient Style
Segments with gradient fills for a modern look.
"use client"
import { DonutChart } from "@/components/ui/charts"
const data = [
{ label: "Sales", value: 45000, color: "#2563eb" },
{ label: "Marketing", value: 32000, color: "#3b82f6" },
{ label: "Development", value: 28000, color: "#60a5fa" },
{ label: "Operations", value: 15000, color: "#93c5fd" },
]
export function DonutChartGradientDemo() {
return (
<div className="w-full max-w-md">
<DonutChart
data={data}
variant="gradient"
innerRadius={0.55}
showLabels
animate
valueFormatter={(value) => `$${(value / 1000).toFixed(0)}k`}
centerLabel="Budget"
showTotal={false}
centerValue="$120k"
/>
</div>
)
}
Separated Segments
Segments with gaps between them.
"use client"
import { DonutChart } from "@/components/ui/charts"
const data = [
{ label: "Completed", value: 68, color: "#2563eb" },
{ label: "In Progress", value: 22, color: "#3b82f6" },
{ label: "Pending", value: 10, color: "#60a5fa" },
]
export function DonutChartSeparatedDemo() {
return (
<div className="w-full max-w-md">
<DonutChart
data={data}
variant="separated"
innerRadius={0.7}
cornerRadius={8}
showLabels
animate
centerLabel="Tasks"
centerValue="156"
showTotal={false}
/>
</div>
)
}
Half Donut (Gauge)
Semi-circle donut for gauge-style displays.
"use client"
import { DonutChart } from "@/components/ui/charts"
const data = [
{ label: "Used", value: 73, color: "#2563eb" },
{ label: "Free", value: 27, color: "#bfdbfe" },
]
export function DonutChartHalfDemo() {
return (
<div className="w-full max-w-md">
<DonutChart
data={data}
innerRadius={0.75}
startAngle={-Math.PI}
endAngle={0}
animate
showLegend={false}
centerLabel="Storage"
centerValue="73%"
showTotal={false}
height={250}
/>
</div>
)
}
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
data | DonutChartDataPoint[] | required | Array of data points |
innerRadius | number | 0.6 | Inner radius ratio (0-1). 0.6 = 60% hollow |
variant | "default" | "gradient" | "separated" | "default" | Visual style |
showLabels | boolean | false | Show percentage labels on segments |
showLabelLines | boolean | true | Show label lines for small segments |
centerLabel | ReactNode | - | Label text in center |
centerValue | ReactNode | - | Value text in center |
showTotal | boolean | true | Show total in center when nothing hovered |
animate | boolean | true | Animate on mount |
animationDuration | number | 750 | Animation duration in ms |
padAngle | number | 0.02 | Gap between segments (radians) |
cornerRadius | number | 4 | Rounded corners on segments |
startAngle | number | -π/2 | Starting angle (top) |
endAngle | number | 1.5π | Ending angle |
sortValues | boolean | false | Sort segments by value |
valueFormatter | function | - | Custom value formatter |
onSegmentClick | function | - | Click handler for segments |
activeIndex | number | - | Controlled active segment |
Data Format
interface DonutChartDataPoint {
label: string // Segment label
value: number // Segment value
color?: string // Optional custom color
}Customization
Custom Colors
const data = [
{ label: "Sales", value: 45, color: "#8B5CF6" },
{ label: "Support", value: 30, color: "#EC4899" },
{ label: "Other", value: 25, color: "#10B981" },
]Custom Value Formatter
<DonutChart
data={data}
valueFormatter={(value, total) => `$${value.toLocaleString()}`}
/>Half Donut (Gauge Style)
<DonutChart
data={data}
startAngle={-Math.PI}
endAngle={0}
innerRadius={0.75}
height={250}
/>Click Handling
<DonutChart
data={data}
onSegmentClick={(item, index) => {
console.log(`Clicked: ${item.label}`)
}}
/>Notes
- The donut chart automatically animates on mount unless
animate={false}is set - Use
innerRadiusbetween 0.5-0.75 for optimal visual balance (0.6 is recommended) - Small segments (< 5%) automatically get label lines when
showLabelLines={true} - The gradient variant applies radial gradients to each segment for a modern look
- For gauge-style displays, use half-circle configuration with
startAngleandendAngle - Segment percentages are calculated automatically from values
- The center content updates on hover to show individual segment details
Deploy and Scale Agents with Simplifying AI
Simplifying AI delivers the infrastructure and developer experience you need to ship reliable audio & agent applications at scale.
Talk to an expert