Components
From opening balance to final result. Show what increased, what decreased, and where the changes leave you.
npx mario-charts@latest add waterfall-chartExplore balances, period subtotals and the steps between them.
Cash movement
Illustrative data · USD
Left to right
Each step shows a change or balance. Use arrow keys to inspect steps, Enter or Space to select, and Escape to dismiss. View data lists every step.
Hover or tap a step to inspect it. Use arrow keys to move, Enter to select, and View data for exact values.
import { WaterfallChart } from "@/components/charts/waterfall-chart";
const steps = [
{ label: "Opening", value: 100000, type: "total" },
{ label: "Sales", value: 45000 },
{ label: "Costs", value: -28000 },
{ label: "Closing", type: "sum" },
] as const;
export function CashFlow() {
return <WaterfallChart data={steps} height={360}
showValues showLegend showGrid
valueFormatter={value => new Intl.NumberFormat("en-US", {
style: "currency", currency: "USD", notation: "compact",
}).format(value)} />;
}| Type | Meaning | Example |
|---|---|---|
| increase / decrease | Adds or subtracts the magnitude. Omit type to use the value’s sign. | { label: "Sales", value: 45000 } |
| total | An absolute balance drawn from zero. Resets the running balance and period checkpoint. | { label: "Opening", value: 100000, type: "total" } |
| sum | Current running balance drawn from zero. Starts a new period checkpoint without changing the balance. | { label: "Closing", type: "sum" } |
| subtotal | Change since the last total, sum or subtotal. Floats from that checkpoint to the current balance. | { label: "Q1 change", type: "subtotal" } |
For gross profit or an ending balance, use sum. For the movement within a period, use subtotal. Computed rows omit value; giving one is an actionable error. Explicit totals keep the original API’s reset behavior.
Floating bars start at the previous balance. The zero line stays visible even when the balance becomes negative. Zero changes use a thin marker; tiny changes retain their true size and remain accessible through larger invisible targets and View data. Long sequences scroll within the chart. No rows are hidden or reordered.
Green and red indicate increases and decreases. For costs or other metrics where lower is better, choose colors that suit your context. Signed labels, step types and inspection carry the meaning alongside color.
Existing numeric increase, decrease and total rows keep their behavior. Numeric strings, missing values and unknown types now show an error instead of silently changing the balance. Custom tooltips can also receive sum and subtotal types and now include the previous balance, geometric start/end and formatted values.
| Prop | Type | Default | Description |
|---|---|---|---|
dataRequired | readonly T[] | — | Ordered steps with a label, finite numeric value and optional type. Order determines the running balance; rows are never sorted or silently removed. |
x / y / type | keyof T | 'label' / 'value' / 'type' | Keys for labels, values and step types. Missing type infers increase or decrease from the sign. |
initialValue | number | 0 | Balance before the first step. Use an opening total row when the initial balance should also have a visible bar. |
orientation | 'vertical' | 'horizontal' | 'vertical' | Horizontal gives long labels more space. Dense sequences scroll inside the fixed frame; keyboard navigation keeps the active step visible. |
variant | 'filled' | 'outline' | 'filled' | Filled bars emphasize contributions; outlines provide a lighter presentation without changing the calculations. |
borderRadius / barWidth | number | 3 / 0.65 | Corner radius 0–24px and category-slot width 0.2–0.9. Radius is capped to fit the actual bar. |
colors | WaterfallColors | — | CSS colors for increase, decrease, total, subtotal and neutral. Sums use the total color. Colors describe direction, not whether a business outcome is good or bad. |
showConnectors / connectorStyle | boolean / 'solid' | 'dashed' | 'dotted' | true / 'dashed' | Connect the previous balance to the next step. An absolute reset to a different balance breaks the connector and is explained in inspection. |
showValues / showLegend / showGrid | boolean | false | Signed value labels, a legend of present roles, and subtle value grid lines. Labels that cannot fit remain available in inspection and View data. |
gridStyle | 'solid' | 'dashed' | 'dotted' | 'dashed' | Style of grid lines. The zero baseline is always visible. |
valueFormatter | (value: number) => string | — | Shared formatter for axes, labels, tooltips and data table. Changes get a + prefix; totals show the formatted absolute balance. |
height | number | 300 | Fixed outer height of at least 180px, including legend and footer. |
animation | boolean | true | Bars grow from their true starting balance, including negative totals. Respects reduced motion; inspection immediately completes the reveal. |
loading / error | boolean / string | null | — | Loading preserves data geometry or shows a waterfall skeleton. All states retain the same root and dimensions. |
onBarClick | (data: T, index: number) => void | — | Original observation and input index, from pointer, touch, keyboard or View data. |
tooltipRenderer | (data: WaterfallChartTooltipData<T>) => ReactNode | — | Original data, index, label, type, signed/computed value, previous balance, geometry start/end, cumulative balance, formatted values and color. |
ariaLabel / description / className | string | — | Accessible chart name, data context and root styling. |