React Bar Chart
A React bar chart compares values as animated bars in grouped, stacked or horizontal layouts, each with tooltips, keyboard reading and a table view. Pass data as readonly ChartRow[]: one object per category: the index key plus one number per series key.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/bar-chart.jsonCustomers per plan
- Free
- Pro
- Team
BarChartBarTabledefaultBarChartLabels- +1 more
Stacked bars: customers per plan
Stacked bars show the total and the split in one mark.
Customers per plan
Last six months
- Free
- Pro
- Team
import { BarChart } from "@/components/sheenui/charts/bar-chart";
import { type ChartSeries } from "@/components/sheenui/charts/chart-utils";
// Package build (after the first npm release, or a packed tarball): import { BarChart, type ChartSeries } from "@sheenui/theme";
const plans = [
{ month: "May", free: 820, pro: 310, team: 90 },
{ month: "Jun", free: 790, pro: 358, team: 111 },
{ month: "Jul", free: 760, pro: 406, team: 132 },
{ month: "Aug", free: 730, pro: 454, team: 153 },
];
const planSeries: ChartSeries[] = [
{ key: "free", label: "Free", color: 1 },
{ key: "pro", label: "Pro", color: 2 },
{ key: "team", label: "Team", color: 3 },
];
export function Example() {
return <BarChart stacked data={plans} index="month" series={planSeries} aria-label="Customers per plan, stacked" />;
}Files to copy
11 folders · 27 files · 4 packages
- From
theme/src/ components/charts/{bar-chart.tsx, chart-annotations.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-sync.tsx, chart-utils.ts}components/charts/chart-parts/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/skeleton/components/status-icons/hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}motion/tokens.tslib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/bar-chart.jsonRegistry item: bar-chart. The styles need the Tailwind v4 glass UI setup.- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".
Horizontal bars
Best for long category names. Values sit at the tip of each bar.
Top countries
Visitors this month
import { BarChart } from "@/components/sheenui/charts/bar-chart";
import { type ChartSeries } from "@/components/sheenui/charts/chart-utils";
// Package build (after the first npm release, or a packed tarball): import { BarChart, type ChartSeries } from "@sheenui/theme";
const countries = [
{ country: "United States", visitors: 48200 },
{ country: "Germany", visitors: 21400 },
{ country: "India", visitors: 18900 },
{ country: "United Kingdom", visitors: 15300 },
{ country: "Brazil", visitors: 9800 },
];
const series: ChartSeries[] = [{ key: "visitors", label: "Visitors", color: 1 }];
export function Example() {
return <BarChart layout="horizontal" showValues data={countries} index="country" series={series} aria-label="Visitors by country" />;
}Patterns
Hatch fills tell the series apart without colour. They switch on by themselves above three series; pass patterns to force them, and give seriesLegend the same flag so the legend swatches match.
Customers per plan
Hatched, so it survives greyscale print
- Free
- Pro
- Team
import { BarChart } from "@/components/sheenui/charts/bar-chart";
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { ChartTable } from "@/components/sheenui/charts/chart-parts/empty-table";
import { seriesLegend } from "@/components/sheenui/charts/chart-parts/legend-tooltip";
import { type ChartSeries } from "@/components/sheenui/charts/chart-utils";
// Package build (after the first npm release, or a packed tarball): import { BarChart, ChartCard, ChartTable, seriesLegend, type ChartSeries } from "@sheenui/theme";
const plans = [
{ month: "May", free: 820, pro: 310, team: 90 },
{ month: "Jun", free: 790, pro: 358, team: 111 },
{ month: "Jul", free: 760, pro: 406, team: 132 },
];
const planSeries: ChartSeries[] = [
{ key: "free", label: "Free", color: 1 },
{ key: "pro", label: "Pro", color: 2 },
{ key: "team", label: "Team", color: 3 },
];
export function Example() {
return (
<ChartCard
title="Customers per plan"
legend={seriesLegend(planSeries, "rect", true)}
table={<ChartTable data={plans} index="month" indexLabel="Month" series={planSeries} />}
>
<BarChart patterns data={plans} index="month" series={planSeries} aria-label="Customers per plan, hatched" />
</ChartCard>
);
}BarChart props
BarChartLabels keys and English defaults (3)
BarTable props
ChartTableLabels keys and English defaults (2)
When to use a bar chart
Use a React bar chart to compare values across categories: plans, countries, products or weeks. Bars start at zero, so their lengths compare honestly. Choose grouped bars to compare series side by side, stacked bars to show a total and its parts, and horizontal bars when the labels are long.
For a ranked list with inline values try the bar list; for positive and negative values, the diverging bar chart; for shares that always add up to 100 percent, the 100% stacked bars. A trend over time reads better in a line chart.
Frequently asked questions
All exports on this page
BarChart— A column or bar chart for comparing values across categories, grouped or stacked, with optional previous-period marks.BarTable— The table view of a BarChart: one row per category, one column per series.defaultBarChartLabels— The built-in English strings of BarChart; spread it into your own labels and change what you need.
Keyboard
Accessibility
- Tab focuses the chart as one stop; the arrow keys read one category at a time and announce each series value in it.
- The Chart / Table tabs switch to a BarTable: one row per category, one column per series, with a caption and row headers; negative values keep their sign.
- With more than three series (or patterns) the bars get hatch fills, so the legend works without color.
- Reduced motion: bars appear at their final length and data changes jump.
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .