Menu

Change language

GitHub repo

Pie Chart

pie-chartui

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

Installation

$npx shadcn@latest add https://uipkge.dev/r/lit/pie-chart.json
Manifest:https://uipkge.dev/r/lit/pie-chart.jsonInstalls to:src/uip/components/charts/

Examples

Loading interactive previews…

Props

NameType / ValuesDefaultRequired
dataRecord<string, any>[][]optional
name-fieldstringnameoptional
value-fieldstringvalueoptional
donutbooleanfalseoptional
optionany—optional

Schema

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

HTMLElementTagNameMap
interface HTMLElementTagNameMap {
    'uip-pie-chart': UipPieChart
  }
}
ChartTheme
interface ChartTheme {
  colors: string[]
  textColor: string
  axisColor: string
  splitLineColor: string
  tooltipBg: string
  tooltipBorder: string
  tooltipText: string
  bgColor: string
  accentColor: string
  dangerColor: string
  /** `--card`: cell borders and inside-label text, so they read as gaps /
   *  contrast on light and dark surfaces (never '#fff'). */
  surfaceColor: string
  /** `--foreground`: primary numbers drawn on the canvas (gauge value). */
  foregroundColor: string
  /** Gauge stoplight from the status tokens, same rule as <uip-usage-bar>:
   *  < 70% success, 70-89% warning, >= 90% destructive. */
  semanticGaugeThresholds: [number, string][]
}

npm dependencies

Includes

Used by

Files installed (4)

  • src/uip/components/charts/pie-chart.ts2.2 kB
    import { ChartElement } from './lib/chart-element'
    
    /**
     * <uip-pie-chart> — the registry PieChart (React `PieChart`) as a web
     * component. Builds the same ECharts option as React for the same props.
     *
     * Properties (React props): `data` (records; JSON attribute or property),
     * `name-field` (default 'name'), `value-field` (default 'value'), `height`
     * (default 300), `donut` (boolean), `option` (ECharts escape hatch, merged
     * like React), `aria-label` (React `ariaLabel`). React's `className` → host classes.
     */
    export class UipPieChart extends ChartElement {
      static properties = {
        data: { type: Array },
        nameField: { attribute: 'name-field' },
        valueField: { attribute: 'value-field' },
        donut: { type: Boolean },
        option: { type: Object },
      }
    
      data: Record<string, any>[] = []
      nameField = 'name'
      valueField = 'value'
      donut = false
      option?: any
      protected readonly chartSlot = 'pie-chart'
    
      protected buildOption() {
        const theme = this.chartTheme
        const chartData = (this.data ?? []).map((d) => ({
          name: d[this.nameField],
          value: d[this.valueField],
        }))
    
        const series = [
          {
            type: 'pie',
            radius: this.donut ? ['45%', '70%'] : '65%',
            center: ['50%', '45%'],
            itemStyle: { borderWidth: 0 },
            label: { show: false },
            data: chartData,
          },
        ]
    
        const userOption: any = this.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 },
            formatter: '{b}: {c} ({d}%)',
          },
          legend: {
            bottom: 0,
            icon: 'circle',
            itemWidth: 8,
            itemHeight: 8,
            textStyle: { fontSize: 11 },
          },
          series: mergedSeries,
          ...userRest,
        }
      }
    }
    
    customElements.get('uip-pie-chart') || customElements.define('uip-pie-chart', UipPieChart)
    
    declare global {
      interface HTMLElementTagNameMap {
        'uip-pie-chart': UipPieChart
      }
    }
    
  • src/uip/components/charts/lib/chart-element.ts4.9 kB
  • src/uip/components/charts/lib/chart-theme.ts7.1 kB
  • src/uip/components/charts/lib/echarts.ts1.9 kB

Raw manifest:https://uipkge.dev/r/lit/pie-chart.json