Waterfall chart
How a total got from one number to another: a start, the gains and losses in between, and the end. Use it for a cash bridge, a budget against actuals, or the change in users over a month. To compare totals that do not build on each other, use the bar chart.
Install
npx shadcn@latest add @thrum-pro/waterfall-chartThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Data shape
type WaterfallChartStep = {
label: string;
value: number | null; // change, or the total to set
kind?: "change" | "total"; // default "change"
};[
{ label: "Opening", value: 42000, kind: "total" },
{ label: "Sales", value: 18400 },
{ label: "Refunds", value: -2300 },
{ label: "Closing", value: null, kind: "total" },
]Props
| Prop | Type | Default | Description |
|---|---|---|---|
data | readonly WaterfallChartStep[] | Required | The steps in order. A change floats from the running total before it to the one after. A total stands on zero: with a value it sets the running total (a starting balance), with null it shows the sum so far (a subtotal or the end). |
label | string | Required | What the running total measures. Read by screen readers and used as the table caption. |
format | Intl.NumberFormatOptions | Default compact | How values are written on the axis, on the bars, in the readout and in the data table. Changes always carry a plus or a minus sign. |
locale | string | Default "en-US" | Locale for number formatting. Fixed by default so the server and the browser print the same text. |
values | boolean | Default true | Write each change, or each total, past the end of its bar: above a rise, below a fall. They are left out when the widest one does not fit its slot. |
yAxis | boolean | Default true | Show value lines and their labels. The axis always includes zero, and the zero line is solid. |
xAxis | boolean | Default true | Show step labels along the bottom. As many as fit are shown, always including the last. |
onActiveChange | (index: number | null) => void | – | Called with the index of the step under the cursor, or null when the cursor leaves. |
sound | boolean | Default true | Play a tick as the cursor moves between steps, if the visitor has sound on. |
emptyLabel | string | Default "No data" | Text shown when no step has a value. |
className | string | – | Sets the size. The default is full width and 288 pixels tall. |
Motion and sound
Motion
- First draw: each bar grows from where it starts in 250 ms, 40 ms apart, and the connector lines fade in after them.
- New data with the same number of steps: bars and connectors move to their new places in 400 ms with no overshoot. A different number of steps switches at once.
- The band behind the active step 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 step, 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 step under the cursor, for example “Refunds: −$2.3K, running total $58.1K” or “Closing: total $36.6K”.
- A visually hidden table carries every step with its change and the running total after it.
- Gains are green and losses red, and never by colour alone: every change carries a plus or a minus sign on the bar, in the readout and in the table, and the readout names it a gain or a loss. Totals are neutral.
- A missing change reads “No data” and leaves the running total as it was.
- The whole plot is the pointer target, so a small change is as easy to read as a large one.
| Keys | Action |
|---|---|
| Tab | Focus the chart. The cursor goes to the last step. |
| ← → | Move the cursor one step. |
| Home / End | Jump to the first or last step. |
| Esc | Hide the cursor. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/waterfall-chart.tsx- Packages
motion- Brings along
- Chart foundationsMotion tokensSound engine
Changelog
- 1.0.0 · 2026-12-03First release.