Skip to content
nexubDesign System
v11.9.0

Components · Data Display

Bar Chart

BetaAdded v3.2.0

Compare values across categories, grouped or stacked. Server-rendered SVG on the chart palette.

import { BarChart } from '@nexub/react';
View as Markdown

Playground

Props

variant
size
legend
Revenue by month
month20262025
May$42k$35k
Jun$48k$37k
Jul$45k$40k
Aug$56k$41k
Sep$61k$47k
Oct$68k$50k
TSX
<BarChart className="w-full" data={data} index="month" series={…} valueFormat={(v) => `$${v}k`} title="Revenue by month" />

Examples

Grouped

Revenue by month
month20262025
May$42k$35k
Jun$48k$37k
Jul$45k$40k
Aug$56k$41k
Sep$61k$47k
Oct$68k$50k

Stacked

Signups by platform
quarterWebiOSAndroid
Q11208060
Q21409572
Q315011090
Q4170128101

Interactive

A crosshair and tooltip, keyboard point navigation, a toggle legend and `onPointClick`.

Signups by platform
quarterWebiOSAndroid
Q11208060
Q21409572
Q315011090
Q4170128101

Click a bar, or focus the chart and press Enter.

Waterfall

Rises in the good tone, falls in danger, totals from zero.

Cash flow, Q3
stepCash
Opening$120K
Sales$64K
Payroll-$52K
Refunds-$6K
Closing$126K
Show as table
Cash flow, Q3
stepCash
Opening$120K
Sales$64K
Payroll-$52K
Refunds-$6K
Closing$126K

Horizontal and per-bar tones

Top products
productRevenue
Enterprise plan (annual)48,200
Team plan31,900
Starter12,800
Spend against a budget of 100
monthSpend
Jan82
Feb97
Mar118

States

  • Revenue by month
    month20262025
    May$42k$35k
    Jun$48k$37k
    Jul$45k$40k
    Aug$56k$41k
    Sep$61k$47k
    Oct$68k$50k
    default
  • loading
  • Revenue by month
    month20262025
    May$42k$35k
    Jun$48k$37k
    Jul$45k$40k
    Aug$56k$41k
    Sep$61k$47k
    Oct$68k$50k
    size="sm"
  • Revenue by month
    month20262025
    May$42k$35k
    Jun$48k$37k
    Jul$45k$40k
    Aug$56k$41k
    Sep$61k$47k
    Oct$68k$50k
    size="md"
  • Revenue by month
    month20262025
    May$42k$35k
    Jun$48k$37k
    Jul$45k$40k
    Aug$56k$41k
    Sep$61k$47k
    Oct$68k$50k
    size="lg"
  • Revenue by month
    month20262025
    May$42k$35k
    Jun$48k$37k
    Jul$45k$40k
    Aug$56k$41k
    Sep$61k$47k
    Oct$68k$50k
    variant="default"
  • Revenue by month
    month20262025
    May$42k$35k
    Jun$48k$37k
    Jul$45k$40k
    Aug$56k$41k
    Sep$61k$47k
    Oct$68k$50k
    variant="waterfall"

Props

Props
PropTypeDefaultDescription
titlerequiredstring—Accessible name of the chart and caption of its data table.
datarequiredT[]—One row per category, in order.
indexrequiredkeyof T & string—Key of the category label in each row (the x axis).
seriesrequiredChartSeries[]—{ key, label?, color? } per series. color is 1–8 from the categorical chart palette; defaults to the series position.
valueFormat((value: number) => string)defaultFormatFormats axis labels, hover text and the data table.
size'sm' | 'md' | 'lg''md'Plot height: 8, 12 or 16rem.
legendfalse | true | 'toggle'trueShow the legend. Defaults to on for more than one series.
stackedbooleanfalseOne bar per category with the series stacked.
series[].color1–8 | 'good' | 'warning' | 'danger' | 'neutral'—11.3: a palette colour or a semantic tone.
series[].valueFormat(value: number) => string—11.3: formats this series in the tooltip and table (one currency per series).
integerTicksboolean—11.3: gridlines on whole numbers only (counts). Also 11.3: a null or missing value is drawn as a gap (no bar, a break in the line) and listed as "—", not counted as 0.
tableViewstring | boolean—11.3: a visible "Show as table" disclosure with the same data. Works without JS.
orientation'horizontal' | 'vertical'—11.3: categories down the side for long names and ranked lists.
variant'default' | 'waterfall''default'11.3: a waterfall of the first series from a running total; totalKey marks rows drawn from zero.
totalKey(keyof T & string)—11.3: a waterfall of the first series from a running total; totalKey marks rows drawn from zero.
colorOf((row: T, series: ChartSeries, index: number) => ChartPaint)—11.3: a colour per bar (e.g. over budget in danger).
defaultHiddenSeriesstring[]—Keys of the series hidden at first.
emptyStateReact.ReactNode—Shown when there is no data. Defaults to the "no data" message.
errorStateReact.ReactNode—Shown in place of the data when a load failed, for example an ErrorState with a retry action. Wins over loading and empty.
hiddenSeriesstring[]—Keys of the hidden series, controlled (10.7).
interactiveboolean—A crosshair and tooltip that follow the pointer, and arrow-key navigation between points.
loadingboolean—Shows a skeleton in place of the data and sets aria-busy.
onHiddenSeriesChange((hidden: string[]) => void)—
onPointClick((point: ChartPoint<T>) => void)—Click, tap, or Enter/Space on a point. Turns interactive on unless it is set to false.

Accessibility

Screen reader

  • The chart is a `figure` named by `title`. The drawing is hidden from assistive tech; a visually hidden table carries every value.

  • Colour is never the only cue: the legend and table name each series. Past six series, label directly or group the rest as "Other".

On iOS & Android