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
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add donut-chart

Or install the full npm package:

npm install bigbullui

Usage

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 helper

Zero 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 />
PropTypeDescription
dataDonutChartDataItem[]Dataset array rendered in charts, grids, or tables. (Default: [])
sizenumberComponent size preset. (Default: 220)
innerRadiusRationumberConfigures inner radius ratio. (Default: 0.62)
padAnglenumberConfigures pad angle. (Default: 2)
formatValue(value: number) => stringConfigures format value. (Default: (val) => val.toLocaleString())
formatPercent(percent: number) => stringConfigures format percent. (Default: (pct) => `${pct.toFixed(1)}%`)
centerLabelstringConfigures center label. (Default: "TOTAL")
centerValuestring | numberConfigures center value.
centerSubtextstringConfigures center subtext.
showCenterTextbooleanToggles show center text. (Default: true)
showTooltipbooleanToggles show tooltip. (Default: true)
showLegendbooleanToggles show legend. (Default: true)
legendPosition"bottom" | "right" | "top" | "none"Configures legend position. (Default: "bottom")
interactivebooleanToggles interactive. (Default: true)
activeIndexnumber | nullConfigures active index.
onActiveChange(index: number | null, item: DonutChartDataItem | null) => voidCallback invoked on active change.
variant"donut" | "pie"Visual style variant. (Default: "donut")
frameVariant"ticket" | "card" | "bare"Configures frame variant. (Default: "ticket")
ticketSerialstringConfigures ticket serial. (Default: "№ DNT-804")
titlestringPrimary heading or title text. (Default: "ADMISSION BREAKDOWN")
subtitlestringSupporting secondary heading text. (Default: "STUB SECTOR ALLOCATION")
classNamestringOptional Tailwind or custom CSS classes merged with component styles.