Sunburst Chart for React
A React sunburst chart shows a hierarchy as rings around a center; click a group to zoom into it with an animated sweep. Pass data as readonly SunburstNode[]: the hierarchy: leaves carry a value; groups carry children (any depth).
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/sunburst-chart.jsonCloud spend by service
SunburstChartSunburstTablesunburstLegenddefaultSunburstChartLabelsdefaultSunburstTableLabels- +3 more
Files to copy
13 folders · 29 files · 4 packages
- From
theme/src/ components/charts/{sunburst-chart.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-tip.tsx, chart-utils.ts, flow-utils.tsx, heatmap.tsx}components/charts/chart-parts/components/charts/heatmap/components/charts/sunburst-chart/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/skeleton/components/status-icons/hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts, use-resolved-scheme.ts}motion/tokens.tslib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/sunburst-chart.jsonRegistry item: sunburst-chart. The styles need the Tailwind v4 glass UI setup.- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".
Zoomable cloud spend
Three levels of a monthly bill. Each service family has its own palette slot; its children share the hue in lighter steps outwards. Click Compute (or press Enter on it) to zoom in. The path can be controlled: the buttons below jump straight to a level.
Cloud spend
October, by service
- Compute
- Storage
- Databases
- Network
- Observability
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { SunburstChart } from "@/components/sheenui/charts/sunburst-chart";
import { sunburstLegend, type SunburstNode } from "@/components/sheenui/charts/sunburst-chart/model";
import { SunburstTable } from "@/components/sheenui/charts/sunburst-chart/parts";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, sunburstLegend, SunburstTable, SunburstChart, type SunburstNode } from "@sheenui/theme";
import { useState } from "react";
const usd = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", notation: "compact", maximumFractionDigits: 1 });
const formatUsd = (n: number) => usd.format(n);
const spend: SunburstNode[] = [
{
label: "Compute",
children: [
{ label: "Kubernetes", children: [{ label: "Web", value: 18400 }, { label: "Workers", value: 9600 }, { label: "Cron jobs", value: 2100 }] },
{ label: "VMs", children: [{ label: "Build agents", value: 7200 }, { label: "Bastion", value: 600 }] },
{ label: "Serverless", value: 3900 },
],
},
{
label: "Storage",
children: [
{ label: "Object storage", children: [{ label: "Media", value: 6800 }, { label: "Backups", value: 4100 }, { label: "Logs", value: 2700 }] },
{ label: "Block storage", value: 5200 },
],
},
// ... Databases, Network, Observability
];
export function Example() {
const [path, setPath] = useState<string[]>([]);
return (
<ChartCard
title="Cloud spend"
legend={sunburstLegend(spend)}
table={<SunburstTable data={spend} format={formatUsd} caption="Spend by service" />}
>
<SunburstChart
data={spend}
path={path}
onPathChange={setPath}
format={formatUsd}
aria-label="Monthly cloud spend by service"
/>
</ChartCard>
);
}Bundle size, two rings
rings={2} shows two levels at a time; deeper ones appear as you zoom in. Arcs too thin for a name stay unlabelled and are read in the center, the tooltip and the table.
Bundle size
Production build, gzip kB
- node_modules
- src
- styles
import { SunburstChart } from "@/components/sheenui/charts/sunburst-chart";
import { type SunburstNode } from "@/components/sheenui/charts/sunburst-chart/model";
// Package build (after the first npm release, or a packed tarball): import { SunburstChart, type SunburstNode } from "@sheenui/theme";
const bundle: SunburstNode[] = [
{
label: "node_modules",
children: [
{ label: "react-dom", value: 132 },
{ label: "motion", value: 58 },
{ label: "@base-ui", children: [{ label: "dialog", value: 14 }, { label: "menu", value: 18 }, { label: "tabs", value: 9 }, { label: "utils", value: 22 }] },
{ label: "tailwind-merge", value: 21 },
{ label: "react", value: 8 },
],
},
{
label: "src",
children: [
{ label: "components", children: [{ label: "charts", value: 96 }, { label: "data-table", value: 41 }, { label: "forms", value: 37 }, { label: "overlays", value: 29 }] },
{ label: "pages", value: 64 },
{ label: "hooks", value: 9 },
],
},
{ label: "styles", value: 31 },
];
export function Example() {
return (
<SunburstChart
data={bundle}
rings={2}
height={300}
format={(kb) => `${kb} kB`}
aria-label="Production bundle size by package and folder"
/>
);
}Flat data: one ring
Without children a sunburst is a single ring, like a donut; every arc gets its own slot. Values below a sliver still get a hairline arc.
Browser share
Sessions, last 30 days
- Chrome
- Safari
- Edge
- Firefox
- Mobile
- Other
import { SunburstChart } from "@/components/sheenui/charts/sunburst-chart";
// Package build (after the first npm release, or a packed tarball): import { SunburstChart } from "@sheenui/theme";
<SunburstChart
data={[
{ label: "Chrome", value: 64.8 },
{ label: "Safari", value: 18.6 },
{ label: "Edge", value: 5.3 },
{ label: "Firefox", value: 2.7 },
{ label: "Mobile", value: 2.4 },
{ label: "Other", value: 6.2 },
]}
height={300}
format={(n) => `${n.toFixed(1)}%`}
aria-label="Browser share of sessions"
/>Props
SunburstChartLabels keys and English defaults (9)
SunburstTable props
SunburstTableLabels keys and English defaults (1)
Keyboard
Accessibility
- The chart is one focusable figure with the role description “sunburst chart”; the breadcrumb is a nav landmark named after the chart, with aria-current on the level shown.
- Moves and zooms are announced through a polite live region (“Compute, Kubernetes: $30.1K, 63% of Compute, 29% of total”, “Compute: 3 items”).
- The center always reads the active arc (or the level shown); the Table view (SunburstTable) lists every node, indented by depth.
- Arc names are drawn in black or white, whichever contrasts more with the fill, and only where they fit.
- Reduced motion: no sweep and no zoom animation; the number in the center jumps.
All exports on this page
SunburstChart— A hierarchy as rings around a centre: each ring is a level, each arc's angle its share.SunburstTable— Every node, depth first (groups in bold, children indented), with its value and shares.defaultSunburstChartLabels— The built-in English strings of SunburstChart; spread it into your own labels and change what you need.defaultSunburstTableLabels— English defaults of SunburstTableLabels.sunburstLegend— Legend items for a sunburst's top-level groups (pass to ChartCard's legend).
When to use the sunburst chart
- Use it as a hierarchical pie chart for a bundle size breakdown, where packages sit in rings by folder and you need to see which branch of the hierarchy owns the weight.
- It fits cloud spend by team and service, or disk usage by folder, where clicking a group zooms into it with an animated sweep.
- It works for flat data too: without children it becomes a single ring like a donut, with every arc taking its own slot and tiny values still getting a hairline arc.
- Skip it when the hierarchy has many tiny leaves or readers must compare sizes precisely; Treemap uses area more efficiently, and a BarChart is better for exact comparison.
- Pair it with ChartCard for the title, SunburstTable for the nested text view with percent of parent and total, and onNodeClick to open details for a leaf.
Frequently asked questions
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .