Chart
Beautiful charts drawn natively with ArkUI Path shapes, styled with the chart-1…5 tokens. Describe series once with SparkChartConfig; every chart measures its own width, thins its labels, animates in with motion key "chart", and shows a shadcn tooltip on hover, tap or horizontal pan.
Usage
Approximate web preview — the HarmonyOS rendering is the reference.
Responsive
No breakpoints: cartesian charts default to a 16:9 box of their own width (160–320vp), skip category labels that would overlap and adapt the number of value ticks to the height.
Sparkline
A tiny inline trend for stat cards and table cells.
Approximate web preview — the HarmonyOS rendering is the reference.
Empty state
SChartContainer({ empty }) shows a muted placeholder.
Approximate web preview — the HarmonyOS rendering is the reference.
API
Extracted from the @Param / @Event / @BuilderParam declarations in the library sources.
SChartContainer
shadcn ChartContainer: card-friendly frame around one or more charts. Shares series visibility with the charts inside it (SparkContext), renders the legend (legend, tap to toggle) and an empty state. It measures its own width: the legend tightens when the container is narrow.
| Prop | Type | Default | Description |
|---|---|---|---|
config | SparkChartConfig | new SparkChartConfig([]) | |
legend | boolean | false | |
legendPlacement | SparkChartLegendPlacementSparkChartLegendPlacement = 'top' | 'bottom' | 'bottom' | |
legendToggle | boolean | true | legend entries toggle their series |
empty | boolean | false | show the empty state instead of the content |
emptyText | ResourceStr | $r('app.string.spark_no_data') | |
emptyHeight | number | 200 |
Slots: children (trailing closure)
SChartLegend
shadcn ChartLegend + ChartLegendContent: centred, wrapping row of swatches. With interactive, tapping an entry hides / shows that series (shared through state).
| Prop | Type | Default | Description |
|---|---|---|---|
config | SparkChartConfig | new SparkChartConfig([]) | |
state | SparkChartState | undefined | undefined | |
keys | string[] | undefined | undefined | keys to list (default: every series of the config); pie charts pass their slice keys |
interactive | boolean | true | |
compact | boolean | false |
SChartTooltipCard
shadcn ChartTooltipContent: label + one row per series (indicator, name, value).
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | '' | |
items | SparkChartTooltipItem[] | [] | |
indicator | SparkChartIndicatorSparkChartIndicator = 'dot' | 'line' | 'dashed' | 'dot' |
SChartEmpty
Muted "no data" block.
| Prop | Type | Default | Description |
|---|---|---|---|
text | ResourceStr | $r('app.string.spark_no_data') | |
boxHeight | number | 200 |
SSparkline
Tiny inline trend line (no axes, no tooltip) — e.g. inside a stat card or a table cell. Fills the width it gets; the value range is the data extent (not forced through 0). Draws in like the other charts.
| Prop | Type | Default | Description |
|---|---|---|---|
values | number[] | [] | |
color | string | 'chart-1' | token name ('chart-1', 'primary' …) or '#hex' |
filled | boolean | true | |
curve | SparkChartCurveSparkChartCurve = 'linear' | 'monotone' | 'step' | 'monotone' | |
chartHeight | number | 32 | |
lineWidth | number | 1.5 | |
endDot | boolean | false | dot on the last value |