Values compared across categories or periods as bars: one series, several side by side, or stacked. Plain SVG.
$ pnpm dlx shadcn@latest add https://dashral.com/r/bar-chart.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/bar-chart.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/bar-chartUsage
import { BarChart } from "@/components/dashral/bar-chart"
<BarChart
data={[
{ month: "Jan", orders: 120 },
{ month: "Feb", orders: 164 },
{ month: "Mar", orders: 198 },
]}
index="month"
series={[{ key: "orders", label: "Orders" }]}
aria-label="Orders by month"
/>Examples
API reference
BarChart
Also takes every prop of <div>(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
data | Record<string, string | number>[]The rows, in order along the x axis. Required. | — |
index | stringThe key for the x axis: a label, or a timestamp or ISO date with timeFormat. Required. | — |
series | { key, label, color?, dashed? }[]What to draw, in order; colors default to --chart-1 … --chart-5. Required. | — |
stacked | booleanOne bar per column with every series in it, its height their total; otherwise side by side. | false |
radius | numberCorner radius of a bar's end; the end on the axis stays square. | 4 |
height | numberIn pixels, axes included; the width follows the container. | 260 |
formatOptions | Intl.NumberFormatOptionsHow values are written in the tooltip, e.g. { style: "currency", currency: "USD" }; the axis writes them compactly. | — |
timeFormat | Intl.DateTimeFormatOptionsReads the index as dates and writes them like this. | — |
showLegend | boolean | more than one series |
showGrid | booleanDashed lines at the axis values. | true |
showYAxis | booleanThe values along the left. | true |
locale | string | the LocaleProvider's |
aria-label | stringWhat the chart shows, e.g. “Revenue by month”. | "Trend from … to …" |
classNames | { legend, tooltip } | — |
Keyboard
| Keys | Action |
|---|---|
| Tab | Focus the chart |
| ←or→ | Read the previous or next point |
| HomeorEnd | The first or last point |
| Esc | Stop reading |
Accessibility
- A group named by your label (by default, how the first series went); the point you move to with the arrow keys is read out with every series' value.
- The x axis runs left to right in every language, as on most charts; the legend and tooltip follow the page's direction.
- The tooltip lists every series by name, so nothing depends on telling colors apart.
Motion
- The bars grow up from the axis when it first shows, and to their new heights when the data changes. Instant with reduced motion.