Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Chart examples · Bar

A multiple bar chart for React

A bar chart grouping desktop and mobile bars side by side for each month.

Framework
UI library

Use grouped bars to compare two series month by month. Desktop and mobile sit side by side in each month, each in its own color, and the tooltip lists both with a dashed indicator.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How are desktop and mobile shown side by side?

Two Bar components share the chart. One uses dataKey desktop and fill var(--color-desktop). The other uses dataKey mobile and fill var(--color-mobile). Both set radius to 4.

Where do the two colors come from?

config sets desktop to var(--chart-1) with the label Desktop, and mobile to var(--chart-2) with the label Mobile. ChartContainer turns those into --color-desktop and --color-mobile.

How are the months abbreviated?

XAxis uses dataKey month and tickFormatter set to formatMonth, the first three characters. axisLine and tickLine are false, and tickMargin is 10. CartesianGrid sets vertical to false.

Why is the tooltip indicator dashed?

ChartTooltipContent sets indicator to dashed, and cursor is false. Hovering a month lists both series, named Desktop and Mobile from config, under that month.

Can I move through the bars with the keyboard?

Yes. BarChart sets accessibilityLayer. Each series has a label in config, which the tooltip reuses for the row name.

What values are paired for each month?

January is desktop 186 and mobile 80, February 305 and 200, March 237 and 120, April 73 and 190, May 209 and 130, and June 214 and 140. Each object is one group of two bars.