Bar chart
Bars spring up one after another. Hover, focus or tap a bar to lift it out with its value while the rest step back; grouped mode sets each bar beside last period's.
npx shadcn@latest add @captain/bar-chartPull requests merged by agents, 23 to 29 Nov
115
Bar chart is a Pro component
The demo and the docs are free. The source comes with Pro, through this page, the shadcn CLI and the MCP.
Usage
import { BarChart } from "@/components/ui/bar-chart"
<BarChart title="Pull requests merged" data={days} grouped compareLabel="Last week" />Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| data | BarDatum[] | { label, name?, value, compare? }. name is the longer label shown above the figure. | |
| title | string | What the bars count. Shown with the total when nothing is picked. | |
| grouped | boolean | false | Adds the compare values as a quieter second bar; toggling it animates. |
| seriesLabel | string | "This period" | Legend name for the main bars. |
| compareLabel | string | "Previous period" | Legend name for the compare bars and the change line. |
| format | Intl.NumberFormatOptions | How values are written. Pass a stable object. | |
| height | number | 180 | Plot height in px. |
Keyboard
- Tab
- Enter the bars
- ← →
- Previous or next bar
- Enter
- Pin the bar
- Esc
- Unpin
Accessibility
- Each bar is a button named with its label and value (and the comparison when grouped). One tab stop, arrows between bars.
- Tap pins a bar on touch, since there is no hover.
- One accent for the picked bar and ink for the rest; no gridlines.
- Reduced motion fades the bars in instead of growing them.