# Bar chart

Free · Charts · version 1.0.1 (2026-12-03)

One metric as vertical bars, one bar per category or period. Use it to compare amounts: orders per day, requests per endpoint. For a continuous trend, use the area chart; for a trend with no axes, use the sparkline.

## Install

```bash
npx shadcn@latest add https://thrumui.dev/r/bar-chart.json
```

Installs by URL into any shadcn/ui project. No configuration needed.

Files: `components/ui/bar-chart.tsx`

Packages: motion
Also installs: thrum-chart, thrum-motion, thrum-sound

Import from `@/components/ui/bar-chart`.

## Usage

```tsx
import { BarChart } from "@/components/ui/bar-chart";

const data = [
  { label: "1 Dec", value: 318 },
  { label: "2 Dec", value: 274 },
  // ...
];

<BarChart
  data={data}
  label="Orders"
  className="h-64"
/>
```

## Data shape

```ts
type BarChartPoint = {
  label: string;        // axis name
  value: number | null; // null = empty slot
};
```

```ts
[
  { label: "Mon", value: 120 },
  { label: "Tue", value: 180 },
  { label: "Wed", value: null },
  { label: "Thu", value: -40 },
]
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `data` | `readonly BarChartPoint[]` | required | Bars in order, left to right. |
| `label` | `string` | required | What the chart measures. Read by screen readers and used as the table caption. |
| `color` | `string` | `var(--chart-1)` | Any CSS colour for the bars. |
| `format` | `Intl.NumberFormatOptions` | `compact` | How values are written on the axis, in the readout and in the data table. |
| `locale` | `string` | `"en-US"` | Locale for number formatting. Fixed by default so the server and the browser print the same text. |
| `yAxis` | `boolean` | `true` | Show value lines and their labels. |
| `xAxis` | `boolean` | `true` | Show bar labels along the bottom. When they do not all fit, every second, third or nth label is shown. |
| `onActiveChange` | `(index: number \| null) => void` |  | Called with the index of the bar under the cursor, or null when the cursor leaves. Use it to sync another chart or a table row. |
| `sound` | `boolean` | `true` | Play a tick as the cursor moves between bars, if the visitor has sound on. |
| `emptyLabel` | `string` | `"No data"` | Text shown when there is nothing to draw. |
| `className` | `string` |  | Sets the size. The default is full width and 256 pixels tall. |

## Motion

- First draw: each bar grows from the zero line in 250 ms. Bars start 40 ms apart, and the whole entrance takes 550 ms at most however many bars there are.
- New data with the same number of bars: each bar moves to its new height in 400 ms with no overshoot, also across the zero line. A different number of bars switches at once.
- The cursor band and the readout follow the pointer on a stiff spring.
- Reduced motion: the chart appears complete, and data changes and the cursor move instantly.

## Sound

- A soft tick each time the cursor lands on a different bar, at most one every 40 ms.

Sound is off until the visitor turns it on. Pass `sound={false}` to keep this component silent.

## Accessibility

- The chart is one tab stop. It is exposed as a slider whose value text is the bar under the cursor, for example “Tue: 180”.
- A visually hidden table carries every bar, with the label as its caption.
- The whole plot is the pointer target, so a short bar is as easy to read as a tall one.
- The cursor is a band behind the active bar. No bar is dimmed, so every bar keeps its contrast against the background.

| Keys | Action |
| --- | --- |
| Tab | Focus the chart. The cursor goes to the last bar. |
| ← → | Move the cursor one bar. |
| Home / End | Jump to the first or last bar. |
| Esc | Hide the cursor. |

## Related

- area-chart: https://thrumui.dev/components/area-chart.md
- sparkline: https://thrumui.dev/components/sparkline.md
- stat-card: https://thrumui.dev/components/stat-card.md

## Changelog

- 1.0.1 (2026-12-03): Corners follow the project's --radius, down to square.
- 1.0.0 (2026-12-02): First release.
