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.
Bar chart, 4 points. Pass to To do. Values from 8 to 42.
Show data table
| Category | Value |
|---|---|
| Pass | 42 |
| Fail | 8 |
| N/A | 12 |
| To do | 24 |
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"
/>Custom height
Section titled “Custom height”Bar chart, 4 points. Perceivable to Robust. Values from 6 to 24.
Show data table
| Category | Value |
|---|---|
| Perceivable | 18 |
| Operable | 24 |
| Understandable | 12 |
| Robust | 6 |
<BarChart
data={[...]}
height={240}
title="Criteria by WCAG principle"
/>Stacked, with selection
Section titled “Stacked, with selection”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 }).
Bar chart, 2 series, 6 points. Q1 to Q3. Values from 8 to 15.
Show data table
| Category | North | South |
|---|---|---|
| Q1 | 12 | 8 |
| Q2 | 15 | 11 |
| Q3 | 9 | 14 |
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}
/>Reference lines
Section titled “Reference lines”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.
Bar chart, 5 points. Mon to Fri. Values from 28 to 45. Daily goal: 40.
Show data table
| Category | Value |
|---|---|
| Mon | 32 |
| Tue | 41 |
| Wed | 28 |
| Thu | 45 |
| Fri | 38 |
<BarChart
data={days}
referenceLines={[{ value: 40, label: 'Daily goal' }]}
title="Issues fixed this week"
/>Accessibility
Section titled “Accessibility”- A
role="figure"named by the visibletitleand described by a generated summary (chart type, series and point counts, range). - The SVG is a
role="group"witharia-roledescription="chart"; nographics-*roles. - Each bar is labelled
{x}: {y}, 2 of 4(several series:{series}, {x}: {y}, 2 of 4, inside arole="group"per series). WithonSelect,selectedIndexor a click handler, marks arerole="button"witharia-pressed; otherwise they’re staticrole="img". - A visible Show data table disclosure (a native
<details>/<summary>, so it opens without JavaScript) reveals a real table captionedData for {title}, withth scopeheaders and values run throughformatValue. - 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.
| Prop | Type | Description |
|---|---|---|
data | BarDatum[] | One bar per category: |
series | BarSeries[] | Several series, as on LineChart: |
direction | “vertical” | “horizontal”Default: | Bar direction. |
categories | string[] | The categories, with |
stacked | booleanDefault: | Stack series. |
xLabel | string | X-axis title. |
yLabel | string | Y-axis title. |
grid | “horizontal” | “vertical” | “both” | “none”Default: | Grid lines. |
formatValue | (value: number) => stringDefault: | Formats values in ticks, marks and the table. Defaults to |
referenceLines | { value: number, label: string }[] | Targets and thresholds across the value axis, as dashed, labelled lines. See Reference lines. |
height | numberDefault: | Plot height in px (horizontal: 36px per bar, min 120). |
aspectRatio | number | Width ÷ height, instead of |
onMarkClick | (mark: { index: BarPointIndex, value, datum: BarDatum }) => void | Called when a mark is clicked (or activated with Enter/Space) with
|
selectedIndex | BarPointIndex | null | The selected bar, |
onSelect | (index | null) => void | Makes bars buttons; called on toggle and Escape. |
title | string | Required. Visible title: names the figure and captions the data table. |
hideTitle | booleanDefault: | Hide the title visually. It still names the chart for assistive technology. |
labels | ChartLabelOverridesDefault: English | Generated strings and the number locale. See Accessibility. |
dataTable | “disclosure” | “visually-hidden” | “none”Default: | 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. |
actions | ReactNode | Shown on the same row as the Show data table button, such as download buttons. |
ref | Ref<HTMLDivElement> | The chart’s root element, e.g. for |
className | string | Class on the figure. |