GitHub

Bar Chart

Compare values across categories, vertically or horizontally.

Loading example…

Installation

pnpm dlx shadcn@latest add @sui/bar-chart

Install with the shadcn CLI or use the shared @workspace/ui package. Follow the installation guide to configure the registry, load styles, and choose import aliases.

Usage

import { BarChart } from "@workspace/ui/charts/bar-chart";

<BarChart data={data} config={config} index="month" />;

Horizontal and stacked

layout="horizontal" puts categories on the y axis. Stacked bars round only the end of the stack.

Loading example…

Negative values

Negative bars use negativeColor. This example formats currency with numberFormatter.

Loading example…

Customize

The wrapper covers common cases. For more control, pass Recharts elements as children, or compose your own chart with the Chart primitives.

API reference

PropTypeDefault / behavior
layout"vertical" | "horizontal""vertical".
stackedbooleanfalse.
radiusnumber8.
negativeColorstringvar(--destructive).
indexstringRequired. The category-axis key.
categoriesreadonly string[]Every key in config.
showGrid / showXAxis / showYAxisbooleanGrid and x axis on; y axis varies by chart.
dir"ltr" | "rtl""ltr". Mirrors the axes.
datareadonly Record<string, unknown>[]Required rows.
configChartConfigRequired. Labels, colors and icons by key; series without a color use --chart-1 to --chart-5.
valueFormatter(value: number) => stringtoLocaleString. Formats axes, tooltip and the screen-reader table; build one with numberFormatter.
showLegendbooleanfalse. Legend buttons show and hide series.
showTooltipbooleantrue.
loadingbooleanfalse. Shows a skeleton.
labelsPartial<ChartLabels>English labels; pass chartLabelsZhCN for Chinese.
aria-labelstringNames the figure and captions its data table.
classNamestringSizes the chart; defaults to a 16:9 box.
childrenReactNodeExtra Recharts elements, such as ReferenceLine.

The module also exports BarChartProps, numberFormatter, and the label presets chartLabels and chartLabelsZhCN. Screen readers get a hidden data table while the drawing itself is hidden from assistive technology, and animation is off when reduced motion is requested.