Skip to content
  • System
  • Light
  • Dark
  • High contrast

BarChart

Pass data as an array of { label, value } objects. Colours default to the raster series palette (--raster-series-*) or can be set per bar with colors.

Conformance results by status

Bar chart, 4 points. Pass to To do. Values from 8 to 42.

01020304050PassFailN/ATo do
Show data table
Data for Conformance results by status
CategoryValue
Pass42
Fail8
N/A12
To do24
import { BarChart } from '@eekodigital/raster';

<BarChart
  data={[
    { label: 'Pass', value: 42, color: 'var(--demo-good)' },
    { label: 'Fail', value: 8, color: 'var(--demo-bad)' },
    { label: 'N/A', value: 12, color: 'var(--demo-neutral)' },
    { label: 'To do', value: 24, color: 'var(--demo-warn)' },
  ]}
  title="Conformance results by status"
/>
Criteria by WCAG principle

Bar chart, 4 points. Perceivable to Robust. Values from 6 to 24.

0510152025PerceivableOperableUnderstandableRobust
Show data table
Data for Criteria by WCAG principle
CategoryValue
Perceivable18
Operable24
Understandable12
Robust6
<BarChart
  data={[...]}
  height={240}
  title="Criteria by WCAG principle"
/>

For several series, pass series ({ name, data }, as on LineChart) with categories. They’re grouped side by side, or stacked. With onSelect, bars become toggle buttons, and selecting one selects that bar ({ series, point }).

Sales by region (select a bar)

Bar chart, 2 series, 6 points. Q1 to Q3. Values from 8 to 15.

051015202530Q1Q2Q3
NorthSouth
Show data table
Data for Sales by region (select a bar)
CategoryNorthSouth
Q1128
Q21511
Q3914

Nothing selected

<BarChart
  series={[
    { name: 'North', data: [12, 15, 9] },
    { name: 'South', data: [8, 11, 14] },
  ]}
  categories={['Q1', 'Q2', 'Q3']}
  stacked
  title="Sales by region (select a bar)"
  selectedIndex={selected}
  onSelect={setSelected}
/>

referenceLines draws dashed, labelled lines across the value axis: vertical for direction="horizontal". The value scale stretches to include each line. They’re named in the summary and the table caption, and aren’t focusable. See LineChart’s reference lines for wording and styling.

Issues fixed this week

Bar chart, 5 points. Mon to Fri. Values from 28 to 45. Daily goal: 40.

01020304050MonTueWedThuFri
Show data table
Data for Issues fixed this week, with a reference line (Daily goal: 40)
CategoryValue
Mon32
Tue41
Wed28
Thu45
Fri38
<BarChart
  data={days}
  referenceLines={[{ value: 40, label: 'Daily goal' }]}
  title="Issues fixed this week"
/>
  • A role="figure" named by the visible title and described by a generated summary (chart type, series and point counts, range).
  • The SVG is a role="group" with aria-roledescription="chart"; no graphics-* roles.
  • Each bar is labelled {x}: {y}, 2 of 4 (several series: {series}, {x}: {y}, 2 of 4, inside a role="group" per series). With onSelect, selectedIndex or a click handler, marks are role="button" with aria-pressed; otherwise they’re static role="img".
  • A visible Show data table disclosure (a native <details>/<summary>, so it opens without JavaScript) reveals a real table captioned Data for {title}, with th scope headers and values run through formatValue.
  • Escape (inside the chart only) hides the tooltip and clears the selection, announcing the cleared selection in a polite live region; it doesn’t close a surrounding dialog.
  • Animations stop under prefers-reduced-motion. In forced-colours mode bars use system colours; with several series, series after the first are outlined with their legend line’s dash pattern.
Key Action
← / → (↑ / ↓ when horizontal) Previous / next mark
Home / End First / last mark
PageUp / PageDown Back / forward 10 marks
↑ / ↓ (stacked: ↑ climbs the stack; ← / → when horizontal) Previous / next series
Tab Leave the chart (one tab stop)
Enter / Space Toggle selection (interactive marks)
Escape Hide the tooltip and clear selection

See the Accessibility guide for the shared structure, the labels prop and screen-reader testing.

PropTypeDescription
dataBarDatum[]

One bar per category: { label, value, color? }. Or use series with categories.

seriesBarSeries[]

Several series, as on LineChart: { name, data, color? }, one value per category. Grouped side by side, or stacked.

direction“vertical” | “horizontal”

Default: “vertical”

Bar direction.
categoriesstring[]

The categories, with series.

stackedboolean

Default: false

Stack series.
xLabelstringX-axis title.
yLabelstringY-axis title.
grid“horizontal” | “vertical” | “both” | “none”

Default: “horizontal”

Grid lines.
formatValue(value: number) => string

Default: Intl.NumberFormat

Formats values in ticks, marks and the table. Defaults to Intl.NumberFormat for labels.locale.

referenceLines{ value: number, label: string }[]

Targets and thresholds across the value axis, as dashed, labelled lines. See Reference lines.

heightnumber

Default: 200

Plot height in px (horizontal: 36px per bar, min 120).
aspectRationumber

Width ÷ height, instead of height. The plot box is sized in CSS either way, so server-rendered and hydrated layouts match.

onMarkClick(mark: { index: BarPointIndex, value, datum: BarDatum }) => void

Called when a mark is clicked (or activated with Enter/Space) with { index, value, datum }; index is what onSelect gives. Makes marks toggle buttons.

selectedIndexBarPointIndex | null

The selected bar, { series, point }. Controlled with onSelect.

onSelect(index | null) => voidMakes bars buttons; called on toggle and Escape.
titlestringRequired. Visible title: names the figure and captions the data table.
hideTitleboolean

Default: false

Hide the title visually. It still names the chart for assistive technology.
labelsChartLabelOverrides
Default: English

Generated strings and the number locale. See Accessibility.

dataTable“disclosure” | “visually-hidden” | “none”

Default: “disclosure”

How the data table is offered: behind a Show data table button, for screen readers only, or not at all, when you offer the data yourself. See Accessibility.

actionsReactNode

Shown on the same row as the Show data table button, such as download buttons.

refRef<HTMLDivElement>

The chart’s root element, e.g. for exportSVG and exportPNG from @eekodigital/raster/export. See Exporting charts.

classNamestringClass on the figure.