Componentcharts3.2 KB gzipZero dependencies
Donut Chart
Interactive SVG donut and pie chart with segment hover highlight, tooltips, center total readout, and custom color legend.
Preview
Live Preview
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add donut-chartOr install the full npm package:
npm install bigbulluiUsage
tsx3 lines
import { DonutChart } from "@/components/ui/donut-chart"; <DonutChart data={[{ label: "VIP", value: 40 }, { label: "General", value: 60 }]} />Source code
donut-chart.tsx + 1 helperZero third-party dependencies (2 local files shown in tabs below).
tsxdonut-chart.tsx546 lines
"use client"; import * as React from "react";import { cn } from "./lib/utils"; export interface DonutChartDataItem { label: string; value: number; color?: string; tone?: "accent" | "primary" | "secondary" | "muted" | "warning" | "success" | "info"; description?: string;} export interface DonutChartProps extends React.HTMLAttributes<HTMLDivElement> { data: DonutChartDataItem[]; size?: number; innerRadiusRatio?: number; padAngle?: number;Props
Interactive Prop Playground
Tweak parsed AST props below to generate ready-to-paste JSX.
tsx3 lines
import { DonutChart } from "@/components/ui/donut-chart"; <DonutChart />| Prop | Type | Description |
|---|---|---|
| data | DonutChartDataItem[] | Dataset array rendered in charts, grids, or tables. (Default: []) |
| size | number | Component size preset. (Default: 220) |
| innerRadiusRatio | number | Configures inner radius ratio. (Default: 0.62) |
| padAngle | number | Configures pad angle. (Default: 2) |
| formatValue | (value: number) => string | Configures format value. (Default: (val) => val.toLocaleString()) |
| formatPercent | (percent: number) => string | Configures format percent. (Default: (pct) => `${pct.toFixed(1)}%`) |
| centerLabel | string | Configures center label. (Default: "TOTAL") |
| centerValue | string | number | Configures center value. |
| centerSubtext | string | Configures center subtext. |
| showCenterText | boolean | Toggles show center text. (Default: true) |
| showTooltip | boolean | Toggles show tooltip. (Default: true) |
| showLegend | boolean | Toggles show legend. (Default: true) |
| legendPosition | "bottom" | "right" | "top" | "none" | Configures legend position. (Default: "bottom") |
| interactive | boolean | Toggles interactive. (Default: true) |
| activeIndex | number | null | Configures active index. |
| onActiveChange | (index: number | null, item: DonutChartDataItem | null) => void | Callback invoked on active change. |
| variant | "donut" | "pie" | Visual style variant. (Default: "donut") |
| frameVariant | "ticket" | "card" | "bare" | Configures frame variant. (Default: "ticket") |
| ticketSerial | string | Configures ticket serial. (Default: "№ DNT-804") |
| title | string | Primary heading or title text. (Default: "ADMISSION BREAKDOWN") |
| subtitle | string | Supporting secondary heading text. (Default: "STUB SECTOR ALLOCATION") |
| className | string | Optional Tailwind or custom CSS classes merged with component styles. |