Captain UI

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-chart
Pro

Pull requests merged by agents, 23 to 29 Nov

115

Usage

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

<BarChart title="Pull requests merged" data={days} grouped compareLabel="Last week" />

Props

PropTypeDefaultWhat it does
dataBarDatum[]{ label, name?, value, compare? }. name is the longer label shown above the figure.
titlestringWhat the bars count. Shown with the total when nothing is picked.
groupedbooleanfalseAdds the compare values as a quieter second bar; toggling it animates.
seriesLabelstring"This period"Legend name for the main bars.
compareLabelstring"Previous period"Legend name for the compare bars and the change line.
formatIntl.NumberFormatOptionsHow values are written. Pass a stable object.
heightnumber180Plot 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.