Skip to content
Thrum

Stacked bar chart

A total per period, split into its parts: revenue by product, requests by status. The height of a bar is the total, and only the bottom part shares a baseline, so use it when the total matters most. To compare the trends of the parts, use the line chart.

Install

npx shadcn@latest add @thrum-pro/stacked-bar-chart

This is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.

Data shape

Type
labels: readonly string[]; // one per bar

type StackedBarChartSeries = {
  key: string;               // stable id
  name: string;              // legend and readout
  values: (number | null)[]; // one per label
  color?: string;
};
Sample
[
  { key: "plans", name: "Plans", values: [620, 655, null, 702] },
  { key: "add-ons", name: "Add-ons", values: [510, 498, 530, 541] },
]

Props

PropTypeDefaultDescription
labelsreadonly string[]RequiredNames of the bars, in order.
seriesreadonly StackedBarChartSeries[]RequiredUp to five series. Each bar stacks them in this order, starting at zero. Negative values stack downwards from zero. A null adds nothing to the bar. A sixth series is drawn in a neutral colour.
labelstringRequiredWhat the chart measures. Read by screen readers and used as the table caption.
formatIntl.NumberFormatOptionsDefault compactHow values are written on the axis, in the readout and in the data table.
localestringDefault "en-US"Locale for number formatting. Fixed by default so the server and the browser print the same text.
yAxisbooleanDefault trueShow value lines and their labels. The axis always includes zero.
xAxisbooleanDefault trueShow bar labels along the bottom. As many as fit are shown, always including the first and last.
legendbooleanDefault trueShow a swatch and a name for each series. It appears when there are two or more series.
onActiveChange(index: number | null) => void–Called with the index of the bar under the cursor, or null when the cursor leaves. Use it to sync another chart or a table row.
soundbooleanDefault truePlay a tick as the cursor moves between bars, if the visitor has sound on.
emptyLabelstringDefault "No data"Text shown when no series has a value.
classNamestring–Sets the size. The default is full width and 256 pixels tall, legend included.

Motion and sound

Motion

  • First draw: each bar grows from the zero line in 250 ms. Bars start 40 ms apart, and the whole group starts within 300 ms however many bars there are.
  • New data with the same number of bars and series: every part moves to its new size in 400 ms with no overshoot. A different number switches at once.
  • The band behind the active bar follows the pointer on a stiff spring.
  • Reduced motion: the chart appears complete, and data changes and the cursor move instantly.

Sound

  • A soft tick each time the cursor lands on a different bar, at most one every 40 ms.

Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works

Accessibility

  • The chart is one tab stop. It is exposed as a slider whose value text is the whole bar, for example “Tue: Plans $620, Add-ons $510, total $1,130”.
  • A visually hidden table carries every value, one column per series and one for the total.
  • A missing value reads “No data” in the readout and in the table, so it is not mistaken for zero.
  • The legend is a plain list. In the readout a colour swatch sits beside each name, and names and values stay in the text colour.
  • The whole plot is the pointer target, so a short bar is as easy to read as a tall one.
KeysAction
TabFocus the chart. The cursor goes to the last bar.
← →Move the cursor one bar.
Home / EndJump to the first or last bar.
EscHide the cursor.

Source

SourcePro

The source comes with Pro

TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies

Files and dependencies

Adds
components/ui/stacked-bar-chart.tsx
Packages
motion
Brings along
Chart foundationsMotion tokensSound engine

Changelog

  1. 1.0.1 · 2026-12-03Corners follow the project's --radius, down to square.
  2. 1.0.0 · 2026-12-02First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor