Skip to content

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.json

Cloud spend by service

Use the arrow keys to read it: left and right go around a ring, down moves out to the children, up moves back in. Press Enter to zoom into a group and Escape to zoom out.

  • SunburstChart
  • SunburstTable
  • sunburstLegend
  • defaultSunburstChartLabels
  • defaultSunburstTableLabels
  • +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.tsx
  • components/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.ts
  • lib/{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

$102.6Kthis month
  • Compute
  • Storage
  • Databases
  • Network
  • Observability
Use the arrow keys to read it: left and right go around a ring, down moves out to the children, up moves back in. Press Enter to zoom into a group and Escape to zoom out.

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
Use the arrow keys to read it: left and right go around a ring, down moves out to the children, up moves back in. Press Enter to zoom into a group and Escape to zoom out.

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
Use the arrow keys to read it: left and right go around a ring, down moves out to the children, up moves back in.

Props

PropTypeDefaultDescription
data (required)readonly SunburstNode[]NoneThe hierarchy: leaves carry a value; groups carry children (any depth).
heightnumber360Height in px; the chart is a circle that fits the smaller of width and height.
ringsnumber3Rings shown at once (deeper levels appear as you zoom in).
drillDownbooleantrue when there are groupsClick / Enter on a group zooms into it.
pathreadonly string[]NoneThe zoomed-in path (group labels from the top), controlled.
defaultPathreadonly string[][]Labels of the group to start zoomed into (uncontrolled).
onPathChange((path: string[]) => void)NoneCalled with the path of labels when the user zooms in or out (controlled path).
onNodeClick((node: { label: string; value: number; path: string[]; }) => void)NoneCalled on click / Enter on a node that has nothing to zoom into.
format((n: number) => string)compact numbers in localeFormats a value for the labels, tooltips and data table: takes the number, returns the text shown.
formatPercent((ratio: number) => string)percentages in localeFormats a share of the total for the tooltips and data table: takes the share, returns the text shown.
localestring"en"Locale of the default number formats.
emptyStateReactNodeNoneShown when there is nothing to plot.
labelsPartial<SunburstChartLabels>defaultSunburstChartLabelsEvery other string, for translation: labels={{ root: "…" }}; omitted keys keep the English of defaultSunburstChartLabels. All 9 keys of SunburstChartLabels are listed in the key table under the props table.
aria-label (required)stringNoneNames the chart for assistive tech (required).
classNamestringNoneAdds extra classes to the outer element.
SunburstChartLabels keys and English defaults (9)
Pass any key in labels; the rest keep the defaults of defaultSunburstChartLabels.
KeyEnglish default
rootTotal
breadcrumbSunburst level
ofParent(parent) => `of ${parent}`
ofTotalof total
instructionsUse the arrow keys to read it: left and right go around a ring, down moves out to the children, up moves back in.
drillInstructionsPress Enter to zoom into a group and Escape to zoom out.
zoomedTo(label, count) => `${label}: ${count} ${count === 1 ? "item" : "items"}`
roleDescriptionsunburst chart
zoomOutZoom out

SunburstTable props

PropTypeDefaultDescription
data (required)readonly SunburstNode[]NoneThe hierarchy: leaves carry a value; groups carry children (any depth).
format((n: number) => string)compact numbers in localeFormats a value for the labels, tooltips and data table: takes the number, returns the text shown.
localestring"en"Locale of the default number formats.
formatPercent((ratio: number) => string)percentages in localeFormats a share of the total for the tooltips and data table: takes the share, returns the text shown.
captionstringNoneHidden caption that names the table for screen readers.
headersPartial<{ name: string; value: string; ofParent: string; ofTotal: string; }>NoneOverride the column headers: { name, value, ofParent, ofTotal }.
labelsPartial<SunburstTableLabels>defaultSunburstTableLabelsStrings for the cells that have no value. Merged over defaultSunburstTableLabels. Every other string, for translation: labels={{ notApplicable: "…" }}; omitted keys keep the English of defaultSunburstTableLabels. Its only key is listed in the key table under the props table.
emptyStateReactNodeNoneShown when there are no rows.
SunburstTableLabels keys and English defaults (1)
Pass any key in labels; the rest keep the defaults of defaultSunburstTableLabels.
KeyEnglish default
notApplicableNot applicable

Keyboard

KeysAction
TabFocus the breadcrumb buttons, then the chart (one stop).
←/→Previous / next arc in the ring (wraps around).
↓Out to the arc's first child.
↑Back in to its parent.
Home/EndFirst / last arc of the ring.
Enter/SpaceZoom into the group (onNodeClick for an arc with nothing to zoom into).
Escape/BackspaceZoom out one level; at the top, Escape clears the reading.

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

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .