Sparkline

Preview

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/sparkline

API Reference

data
readonly (number | null)[]

Samples in display order. Missing or non-finite values leave a gap.

Default—
labels?
readonly string[]

Optional sample labels, such as dates, used by the interactive readout.

Default—
label
string

Accessible name, such as "Revenue, last 30 days".

Default—
variant?
"area" | "line"
Defaultline
curve?
"step" | "monotone" | "linear"
Defaultmonotone
color?
string

Any CSS color. Defaults to the current text color.

DefaultcurrentColor
height?
number

Height in px. Width follows the container.

Default32
strokeWidth?
number
Default1.5
showDelta?
boolean

Show the change from the first to the last sample as a badge.

Defaultfalse
invertDelta?
boolean

Color a fall green and a rise red, for metrics where lower is better, such as error rate.

Defaultfalse
interactive?
boolean

Hover, drag or arrow keys to read individual samples. Adds one tab stop.

Defaultfalse
formatValue?
((value: number) => string)
Default(value) => number.format(value)
messages?
Partial<{ inspect: string; sample: string; sampleValue: string; range: string; up: string; down: string; } & { noData: string; missing: string; dataCaption: string; category: string; total: string; series: string; seriesValue: string; totalValue: string; }>

Override any built-in string, including the shared `xyChart` ones. Named `messages` because `labels` already holds the sample labels.

Default—
className?
string
Default—

Updated