Skip to content

Pie Chart ​

Pie and donut charts. Slices sweep in, the hovered / tapped slice grows, the legend toggles slices.

Usage ​

Approximate web preview — the HarmonyOS rendering is the reference.

Donut with text ​

Approximate web preview — the HarmonyOS rendering is the reference.

Separated + legend ​

Approximate web preview — the HarmonyOS rendering is the reference.

API ​

Extracted from the @Param / @Event / @BuilderParam declarations in the library sources.

SPieChart ​

shadcn "Pie Chart" / "Donut": one slice per data row (row label = slice key in config, which gives its label and colour), sized by valueKey. Slices sweep in on appear and morph when data or the legend change. Tap / hover a slice for its tooltip; the active slice grows (activeGrow).

PropTypeDefaultDescription
configSparkChartConfignew SparkChartConfig([])
dataSparkChartRow[][]
valueKeystring'value'the row value drawn as slice size
innerRationumber0inner radius as a fraction of the outer radius (0 = pie, ~0.6 = donut)
padAnglenumber0gap between slices in degrees
chartHeightnumber250maximum diameter in vp (the chart is square and never wider than its container)
centerValuestring''big text in the middle of a donut (e.g. the total)
centerLabelstring''
activeGrowbooleantrue
tooltipbooleantrue
legendbooleanfalse
indicatorSparkChartIndicator
SparkChartIndicator = 'dot' | 'line' | 'dashed'
'dot'
valueFormatter(value: number) => stringdefaultValue
emptyTextResourceStr$r('app.string.spark_no_data')
EventTypeDefaultDescription
onActiveChange(index: number) => void() => { }

SDonutChart ​

SPieChart with a hole (innerRatio 0.6) and an optional centre label (shadcn "Pie Chart - Donut Text").

PropTypeDefaultDescription
configSparkChartConfignew SparkChartConfig([])
dataSparkChartRow[][]
valueKeystring'value'
innerRationumber0.6
padAnglenumber0
chartHeightnumber250
centerValuestring''
centerLabelstring''
activeGrowbooleantrue
tooltipbooleantrue
legendbooleanfalse
indicatorSparkChartIndicator
SparkChartIndicator = 'dot' | 'line' | 'dashed'
'dot'
valueFormatter(value: number) => stringdefaultValue
emptyTextResourceStr$r('app.string.spark_no_data')
EventTypeDefaultDescription
onActiveChange(index: number) => void() => { }

MIT Licensed