UIPackage
Menu

Framework

Change language

Boilerplate repo

Sunburst Chart

sunburst-chartui

React mirror of @uipkge/sunburst-chart — see the Vue registry item for the canonical description.

Also available for Vue ->

Installation

$npx shadcn@latest add https://uipkge.dev/r/react/sunburst-chart.json
Named registry:npx shadcn@latest add @uipkge-react/sunburst-chartInstalls to:components/ui/charts/sunburst-chart/

Examples

Loading interactive previews…

Props

NameType / ValuesDefaultRequired
data

Hierarchical data — top-level array, each node has `name`, optional `value`, optional `children`.

SunNode[]required
heightnumber | string360optional
radius

Inner / outer radius as percentages of the smaller container side. Default `['12%', '90%']`.

[string, string]optional
optionanyoptional
classNamestringoptional
ariaLabel

Accessible name announced for the chart image. Defaults to "Chart".

stringoptional

Schema

Type aliases from this item's source — use them to shape the data you pass in.

SunNode
interface SunNode {
  name: string
  value?: number
  children?: SunNode[]
}
ChartTheme
interface ChartTheme {
  colors: string[]
  textColor: string
  axisColor: string
  splitLineColor: string
  tooltipBg: string
  tooltipBorder: string
  tooltipText: string
  bgColor: string
  /** The app's accent, for the one highlighted element on a chart or map —
   *  a selected route, a focused bar. Category series keep using `colors`. */
  accentColor: string
  /** Out-of-bounds / failure colour for charts that encode good vs bad
   *  rather than a category — control limits, error series. CSS-level marks
   *  can use `var(--destructive)` directly; this exists because ECharts needs
   *  a resolved colour string on the canvas. */
  dangerColor: string
}

npm dependencies

Used by

Files installed (4)

  • components/ui/charts/sunburst-chart/SunburstChart.tsx2.1 kB
    'use client'
    
    import * as React from 'react'
    import ReactECharts from 'echarts-for-react/esm/core'
    import { ChartFrame, EChart } from '../shared'
    import { useChartTheme } from '../useChartTheme'
    
    // SunburstChart
    // ─────────────────────────────────────────────────────────────────────────
    
    interface SunNode {
      name: string
      value?: number
      children?: SunNode[]
    }
    
    export interface SunburstChartProps {
      /** Hierarchical data — top-level array, each node has `name`, optional `value`, optional `children`. */
      data: SunNode[]
      height?: number | string
      /** Inner / outer radius as percentages of the smaller container side. Default `['12%', '90%']`. */
      radius?: [string, string]
      option?: any
      className?: string
      /** Accessible name announced for the chart image. Defaults to "Chart". */
      ariaLabel?: string
    }
    
    export const SunburstChart = React.forwardRef<HTMLDivElement, SunburstChartProps>(
      ({ data, height = 360, radius = ['12%', '90%'], option, className, ariaLabel }, ref) => {
        const theme = useChartTheme()
    
        const mergedOption = React.useMemo(() => {
          const series = [
            {
              type: 'sunburst',
              radius,
              data,
              label: { rotate: 'radial' as const, fontSize: 11 },
              itemStyle: { borderColor: '#fff', borderWidth: 1 },
              emphasis: { focus: 'ancestor' as const },
            },
          ]
    
          const userOption: any = option ?? {}
          const { series: userSeries, ...userRest } = userOption
          const mergedSeries = Array.isArray(userSeries)
            ? series.map((s, i) => ({ ...s, ...(userSeries[i] ?? {}) }))
            : series
    
          return {
            color: theme.colors,
            tooltip: {
              trigger: 'item',
              backgroundColor: theme.tooltipBg,
              borderColor: theme.tooltipBorder,
              textStyle: { color: theme.tooltipText, fontSize: 12 },
            },
            series: mergedSeries,
            ...userRest,
          }
        }, [data, radius, option, theme])
    
        return (
          <ChartFrame ref={ref} height={height} className={className} ariaLabel={ariaLabel}>
            <EChart option={mergedOption} />
          </ChartFrame>
        )
      },
    )
    SunburstChart.displayName = 'SunburstChart'
    
  • components/ui/charts/sunburst-chart/index.ts0.1 kB
  • components/ui/charts/useChartTheme.ts8.7 kB
  • components/ui/charts/shared.tsx3.7 kB

Raw manifest:https://uipkge.dev/r/react/sunburst-chart.json