On this page

Charts

RankedBars

A ranked list: one horizontal bar per item, sorted by size, with the label on the left and the value on the right. An optional muted column adds a detail such as a job count.

When to use it #

Use RankedBars for “what is the biggest” questions: overruns by category, hours by technician, top customers. It sorts by the size of the value (sort), can cut the list (limit), and gives long labels a tooltip. By default the bars are solid: fill is 'solid'. Pass fill="hatch" for the look of a plan or a reference, so a list of planned values doesn’t pass for actuals. fill also accepts a function, to hatch only some rows. When each row has both a plan and an actual, use ComparisonBars instead.

Import #

Terminal
npm i tally-charts
app/overruns.tsx
import { RankedBars } from 'tally-charts'
import 'tally-charts/theme.css'

Examples #

No fill prop: the bars are 'solid', the default. tone="loss" colors the bars and the values.

Cost overruns by category
View of Cost overruns by category
Cost overruns by category
CategoryAmount
Labor overruns$31.2K
Material waste$18.4K
Rework$12.9K
Equipment rental$7.6K
Permits$2.1K

fill="hatch" marks the bars as a plan. meta adds the muted “9 jobs” column before the value.

Planned hours by technician
View of Planned hours by technician

With onSelect and selectedId, a row can drive something else on the page. Focus the chart and press Enter or Space on a row.

Overruns by category, pick a row
View of Overruns by category, pick a row

Bars show magnitudes, so a negative "lost" amount extends to the right like the others and keeps its sign in the text.

Props #

NameTypeDefaultRequiredDescription
activeIdId | null—No—
animateboolean—No—
aria-labelledbystring—No

Id of an element that names the chart; it wins over title for the name.

barSizenumber12 (inline) or 6 (stacked)No

Default 12 (inline) or 6 (stacked).

chartIdstring—No

Prefix for pattern and mask ids. React's useId is only unique within one root, so set this when charts render in several React roots on one page.

childrenReactNode—No—
classNamestring—No—
datareadonly D[]—Yes—
dataTableboolean | DataTableOptionstrueNo

Hidden data table for screen readers: true, false, or { caption, columns } to set its caption and rename column headers. Default true.

descriptionstring—No

Accessible description, usually the takeaway sentence.

dimInactiveboolean—No—
domainreadonly [number, number]zero to the largest magnitudeNo

Domain of bar lengths. Default: zero to the largest magnitude.

emptyReactNode"No data"No

Rendered instead of the plot when data is an empty array. Default "No data".

fillPerItem<D, Fill>'solid'No

Default 'solid'. Use 'hatch' for a plan or reference look.

formatFormatSpec'number'No

Default 'number'.

heightnumber240 unless `aspectRatio` is setNo

Height in px. Default 240 unless aspectRatio is set.

idAccessor<D, Id>the data indexNo

Row id passed to onSelect and compared with selectedId. Default: the data index.

initialWidthnumber640No

Width used for server rendering and the first client render. Default 640.

keyboardHintstring"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 onSelect. A custom text is used as is. Set it to translate the text; "" turns it off.

labelAccessor<D, string>—Yes—
labelWidthnumber—No

Inline label column width in px (default 140). In the stacked layout, a max label width.

layout'inline' | 'stacked''inline'No

'inline': label | bar | value on one line. 'stacked': label and value above a thin bar. Default 'inline'.

limitnumber—No

Show only the first rows after sorting.

marginPartial<Margin>—No—
metaAccessor<D, string>—No

Muted text before the value, e.g. "9 jobs".

metaWidthnumber64No

Meta column width in px. Default 64.

onActiveChange(id: Id | null, point: ChartPoint<D> | null) => void—No

Called with the new active id, and its point; point.datum is the row from data.

onSelect(id: Id, point: ChartPoint<D>) => void—No

Called on click, Enter or Space; point.datum is the row from data.

rowHeightnumber40 (inline) or 52 (stacked)No

Default 40 (inline) or 52 (stacked).

selectablePerItem<D, boolean>trueNo

False for rows onSelect skips, e.g. an "Other" row that can't be a filter. They still take hover, focus and the tooltip. Default true.

selectedIdId | null—No

The highlighted row. Hover and focus stay separate (activeId).

selectedToneTone'loss'No

Tone of the selected row's bar and value. Default 'loss'.

sort'desc' | 'asc' | 'none''desc'No

By size of the value, ignoring its sign. Default 'desc'.

styleCSSProperties—No—
titlestring—No

Accessible name of the chart; also the default caption of the data table.

tonePerItem<D, Tone>'neutral'No

Default 'neutral'. A non-neutral tone also colors the value text.

tooltipChartTooltip<D>trueNo

Tooltip on hover and focus, so cut labels stay readable: true for the default pill (full label and value), or a function that renders the content for a point. Default true.

trackbooleantrueNo

Faint track behind each bar. Default true.

valueAccessor<D, number>—Yes—
valueWidthnumber72No

Inline value column width in px. Default 72.

widthnumber—No

Fixed width in px; turns off container measuring.

Keyboard and screen readers #

RankedBars is built on Chart, so it follows the same keyboard model as the other charts: the list is a single tab stop, and tabbing in shows the first row with its tooltip and announces it. Arrow keys move between rows (rows are sorted, so “previous” and “next” follow the order on screen), Home and End jump to the first and last row, Enter or Space selects the active row when the chart has onSelect, and Esc clears the active row. Esc is only consumed when a row is active, so an enclosing dialog still closes. A row with selectable: false takes focus and a tooltip but Enter skips it.

Screen readers get the chart title and description, then an announcement for each row the keyboard moves to, in the form “1 of 5, Labor overruns, $31.2K”. With meta the detail is added: “1 of 5, Tyler Brooks, $2.6K, 9 jobs”. A visually hidden data table with the label, the value and the details follows the chart. Hatch is only a visual cue, so say in the title or description when a list shows a plan.

The full model is in the accessibility guide.