Skip to documentation content

Waterfall Chart

Show how a starting value becomes an ending value through a sequence of increases and decreases.

Operating income bridge

Overview

Use a waterfall chart, also called a bridge chart, to explain a change between two totals: how revenue became operating income, how last month's users became this month's, or how a budget was spent. Each step floats from where the previous one ended, so the size of every contribution and the running total are both visible.

Rows are ordered steps. Most rows carry a change. Rows marked as totals span from zero to the running total, for subtotals and the final result. A total row with a value resets the running total to it, which is how an opening balance is set.

Anatomy

WaterfallChart computes the running total from data and owns the axes and loading state. Bars draws the floating bars, dashed connectors that carry the running total from one bar to the next, and optional value labels. Add XAxis, YAxis, Grid, Legend, and Tooltip for context.

Colors come from three config keys: increase, decrease, and total. Bars that cross zero are drawn correctly, because every bar is a range from its start to its end, not a stack on a hidden base.

Accessibility

Do not rely on green and red alone: label the steps clearly, consider showValues so each change is printed with its sign, and choose colors that differ in lightness. The canvas exposes only its accessible name, which by default reports the number of steps and the final total. computeWaterfall returns exactly what the chart draws, so the same steps can fill a nearby table.

Installation

npm install honestui

Usage

import { WaterfallChart, type ChartConfig } from "honestui/charts";
const data = [
  { step: "Revenue", amount: 1840, isTotal: true },
  { step: "Cost of goods", amount: -612 },
  { step: "Gross profit", isTotal: true },
  { step: "Salaries", amount: -428 },
  { step: "Operating income", isTotal: true },
];

const chartConfig = {
  increase: { label: "Increase", colors: { light: ["#16a34a"] } },
  decrease: { label: "Decrease", colors: { light: ["#dc2626"] } },
  total: { label: "Total", colors: { light: ["#2563eb"] } },
} satisfies ChartConfig;

<WaterfallChart
  data={data}
  config={chartConfig}
  xDataKey="step"
  valueDataKey="amount"
  totalDataKey="isTotal"
>
  <WaterfallChart.Grid />
  <WaterfallChart.XAxis />
  <WaterfallChart.YAxis />
  <WaterfallChart.Tooltip />
  <WaterfallChart.Bars />
</WaterfallChart>

The tooltip shows each step's change with its sign and the running total after it.

Examples

Value Labels

showValues

showValues prints each change above rising bars and below falling ones. Use valueFormatter to shorten large numbers; it receives the bar's kind so totals can be written without a sign.

Reference Line

<WaterfallChart.ReferenceLine />

A ReferenceLine at the plan or budget shows where the result lands against it. ReferenceArea and ReferenceDot work the same way; see Reference Lines. Give several waterfalls, or a waterfall and a bar chart over the same steps, one syncId to move their tooltips together.

Loading State

isLoading='true'

isLoading reserves the plot with a neutral bridge silhouette and the shared loading label.

API Reference

WaterfallChart
PropTypeDefaultDescription
data*TData[]–

One row per step, in order.

config*ChartConfig–

Labels and colors for increase, decrease, and total.

xDataKey*keyof TData & string–

The step name.

valueDataKey*keyof TData & string–

The change each step contributes. On a total row, an optional value that resets the running total.

totalDataKeykeyof TData & string–

A boolean field that marks total and subtotal rows.

animationbooleantrue

Fades the bars in from left to right. Reduced-motion preferences turn it off.

isLoadingbooleanfalse

Shows the loading silhouette and label.

syncIdstring–

Charts with the same id move their tooltip together, matched by step name.

ariaLabelstring–

Accessible name for the canvas. A summary with the final total is generated when omitted.

chartOptionsRecord<string, unknown>–

Escape hatch merged over the generated ECharts option.

Bars
PropTypeDefaultDescription
radiusnumber2

Corner radius in pixels.

widthnumber0.6

Bar width as a share of each category.

connectorsbooleantrue

Draws dashed connectors at the running total between bars.

showValuesbooleanfalse

Prints each change beside its bar.

valueFormatter(value: number, kind: "increase" | "decrease" | "total") => string–

Formats the printed values.

XAxis / YAxis
PropTypeDefaultDescription
tickFormatter(value, index: number) => string–

Formats tick labels. Steps are strings and values are numbers.

labelstring–

Axis title.

hideDotsbooleanfalse

Hides the tick dots.

Tooltip
PropTypeDefaultDescription
variantdefault|frosted-glass"default"

Tooltip surface.

roundnesssm|md|lg|xl"lg"

Tooltip corner radius.

positionfixed|variable"variable"

Pins the tooltip to the top or lets it follow the pointer.

cursorbooleanfalse

Draws the dashed line at the hovered step.

valueFormatter(value: number) => string–

Formats the change and the running total.

defaultIndexnumber–

Opens the tooltip at a step after mount.

Legend
PropTypeDefaultDescription
variantLegendVariant"rounded-square"

Indicator shape. Only kinds present in the data are listed.

alignleft|center|right"right"

Horizontal alignment.

verticalAligntop|middle|bottom"top"

Vertical placement.

ReferenceLine, ReferenceArea, ReferenceDot

Take the props listed in Reference Lines. Pass a step name for x and an amount for y.

computeWaterfall

computeWaterfall(data, xKey, valueKey, totalKey?) returns one WaterfallStep per row with its kind, value, start, end, and runningTotal, the same numbers the chart draws.