Charts
BridgeChart
A bridge in vertical columns: the start, then a column for the running total after each change. Each column carries a cap for the change that led to it, the new total above and a short note below.
When to use it #
Use BridgeChart when the totals matter as much as the changes: a quote that shrinks to the profit you kept, a budget that is spent down in stages. Each column is a running total, so a reader can see what was left after every step. The cap on a column marks the change (loss or gain), note names it (“−$260 discount”), and a gradient area joins the totals (area={false} removes it). The last column is solid and emphasized; highlightLast={false} keeps it as hatched as the rest. A callout pins a pill above the last column for the headline numbers, such as “$400 kept | 12.3% margin”.
If you want one row per change that ends in a calculated total, use WaterfallChart. A bridge shows the totals, a waterfall shows the changes between them.
Import #
npm i tally-chartsimport { BridgeChart } from 'tally-charts'
import 'tally-charts/theme.css'Examples #
Every step has a note, the short word that follows the change. highlightLast={false} keeps the last column hatched like the others, for a result that is not the point of the chart.
| Column | Change | Total |
|---|---|---|
| Quoted | no value | $48,000 |
| After change orders | +$3,600 change orders | $51,600 |
| After discounts | −$2,400 discounts | $49,200 |
| After retainage | −$3,000 retainage | $46,200 |
| After write-offs | −$1,700 write-offs | $44,500 |
import { BridgeChart } from 'tally-charts'
import type { ExampleMeta } from '../types'
export const meta = {
id: 'bridge-chart/quote-to-cash',
title: 'From quote to cash collected',
rscSafe: true,
} satisfies ExampleMeta
const steps = [
{ label: 'After change orders', value: 3600, note: 'change orders' },
{ label: 'After discounts', value: -2400, note: 'discounts' },
{ label: 'After retainage', value: -3000, note: 'retainage' },
{ label: 'After write-offs', value: -1700, note: 'write-offs' },
]
// Each `note` is the short word after the change. highlightLast={false} keeps the last column hatched like the rest.
export default function QuoteToCash() {
return (
<BridgeChart
title={meta.title}
description="A $48,000 quote grew to $51,600 with change orders, then fell to $44,500 after discounts, retainage and write-offs."
start={{ label: 'Quoted', value: 48000 }}
steps={steps}
format="currency"
highlightLast={false}
/>
)
}
callout is an array of segments, so it stays serializable: the pill sits above the last column, which is solid by default (highlightLast).
import { BridgeChart } from 'tally-charts'
import type { ExampleMeta } from '../types'
export const meta = {
id: 'bridge-chart/job-profit',
title: 'Estimated profit to profit kept, one job',
rscSafe: true,
} satisfies ExampleMeta
const steps = [
{ label: 'After permits', value: -300, note: 'permits' },
{ label: 'After rework', value: -450, note: 'rework' },
{ label: 'After rental', value: -250, note: 'rental' },
{ label: 'After travel', value: -200, note: 'travel' },
]
// `callout` is an array of segments, so it stays serializable. It is aria-hidden: the numbers are in `description` too.
export default function JobProfit() {
return (
<BridgeChart
title={meta.title}
description="Estimated profit of $2,400 shrank to $1,200 after permits, rework, rental and travel. The job kept 50% of the estimate."
start={{ label: 'Estimated profit', value: 2400 }}
steps={steps}
format="currency"
callout={[
{ value: '$1,200', label: 'kept' },
{ value: '50%', label: 'of estimate' },
]}
/>
)
}
What a step leaks (or gains) is drawn as a hatched cap on its column. The callout pill is lifted clear of any column labels it reaches over.
Props #
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
activeId | Id | null | — | No | — |
animate | boolean | — | No | — |
area | boolean | true | No | Gradient area joining the column totals. Default true. |
aria-labelledby | string | — | No | Id of an element that names the chart; it wins over |
callout | readonly TooltipSegment[] | — | No | A pill pinned above the last column, e.g. |
chartId | string | — | No | Prefix for pattern and mask ids. React's |
children | ReactNode | — | No | — |
className | string | — | No | — |
dataTable | boolean | DataTableOptions | true | No | Hidden data table for screen readers: |
description | string | — | No | Accessible description, usually the takeaway sentence. |
dimInactive | boolean | — | No | — |
domain | readonly [number, number] | zero to the largest total, rounded to nice ticks | No | Value domain. Default: zero to the largest total, rounded to nice ticks. |
empty | ReactNode | "No data" | No | Rendered instead of the plot when |
format | FormatSpec | 'number' | No | Default 'number'. |
height | number | 240 unless `aspectRatio` is set | No | Height in px. Default 240 unless |
highlightLast | boolean | true | No | Solid, highlighted last column with an emphasized label. Default true. |
initialWidth | number | 640 | No | Width used for server rendering and the first client render. Default 640. |
keyboardHint | string | "Use arrow keys to move between points, Home and End for first and last, Escape to clear.", plus " Press Enter to select." while the active point (or the first, before one is active) can be selected with `onSelect` | No | Instructions read with the chart when it takes keyboard focus. Default: "Use arrow keys to move between points, Home and End for first and last, Escape to clear.", plus " Press Enter to select." while the active point (or the first, before one is active) can be selected with |
margin | Partial<Margin> | — | No | — |
onActiveChange | (id: Id | null, point: ChartPoint<D> | null) => void | — | No | Called with the new active id, and its point; |
onSelect | (id: Id, point: ChartPoint<D>) => void | — | No | Called on click, Enter or Space; |
padding | number | 0.45 | No | Inner band padding, 0–1. Default 0.45. |
start | BridgeStart | — | Yes | — |
stepLabel | (step: S) => string | the signed change plus the note | No | Text under each column total. Default: the signed change plus the note. |
steps | readonly S[] | — | Yes | — |
style | CSSProperties | — | No | — |
title | string | — | No | Accessible name of the chart; also the default caption of the data table. |
tooltip | ChartTooltip<S | BridgeStart> | true | No | Tooltip on hover and focus: |
width | number | — | No | Fixed width in px; turns off container measuring. |
Keyboard and screen readers #
BridgeChart is built on Chart, so it follows the same keyboard model as the other charts: it is a single tab stop, and tabbing in shows the first column with its tooltip and announces it. Arrow keys move to the previous or next column, Home and End jump to the first and last, Enter or Space selects the active column when the chart has onSelect, and Esc clears the active column. Esc is only consumed when a column is active, so an enclosing dialog still closes. The widget’s description ends with a keyboard hint (“Use arrow keys to move between points, Home and End for first and last, Escape to clear.”, plus “Press Enter to select.” with onSelect); keyboardHint replaces it, for example to translate it, and keyboardHint="" turns it off.
Screen readers get the chart title and description, then an announcement for each column the keyboard moves to, in the form “2 of 5, After discount, $1,000, −$260 discount”: its position, label, running total and the change with its note. A visually hidden data table with the columns Column, Change and Total follows the chart; dataTable renames the caption and headers, or turns it off.
The SVG and the HTML overlay are aria-hidden, so a callout says nothing to a screen reader. Put the same facts in the title, the description or the notes, as the job-profit example does with the profit kept. In a very narrow chart BridgeChart shows only some column totals and no notes, and a pinned pill can take three lines; the tooltip and the data table still have everything.
The full model is in the accessibility guide.