When to use a bar chart
Use a bar chart to compare values across a handful of categories or periods, where the exact height of each bar matters.
- Monthly revenue vs. expenses
- Signups per channel or campaign
- Stacked composition, e.g. revenue by plan per month
- 100% stacked shares when proportions matter more than totals
Data format
- Column 1 is the category axis (months, channels, dates); every other column becomes a series of bars.
- Dates like 2024-01-01 get short date ticks automatically.
- Paste CSV, JSON from your API, TSV copied from Excel or Google Sheets, or a Markdown table. The generated component keeps your column names as its data keys.
Month,Revenue,Expenses
Jan,42000,31000
Feb,58000,34000
Mar,51000,29000
Apr,67000,38000
May,72000,41000
Jun,69000,37000[
{"month": "Jan", "revenue": 42000, "expenses": 31000},
{"month": "Feb", "revenue": 58000, "expenses": 34000},
{"month": "Mar", "revenue": 51000, "expenses": 29000},
…
]Options
- Grouped / Stacked / 100%
- Side-by-side bars, stacked totals, or each bar normalized to 100%.
- Tooltip
- A breakdown tooltip with each series' share of the bar, or shadcn's default tooltip.
- Colors
- Pick any color per series; the copied chartConfig updates to match.
- Inline data / Data as prop
- Bake your data into the component or accept it as a typed data prop.
How to add it to your project
- 1. Add the shadcn/ui chart component (it installs Recharts):
npx shadcn@latest add chart - 2. Paste your data above, pick the options, and copy the generated
chart.tsx. - 3. Save it in your project (e.g.
components/bar-chart.tsx) and render<Chart />, or<Chart data={rows} />in Data as prop mode.
Bar Chart FAQ
Choose Stacked in the Layout control. The generated code gives every <Bar> the same stackId and rounds only the top segment, so the stack reads as one bar.
Yes. Paste a sample of your API's JSON, switch the code to Data as prop, and pass the response straight in. The component uses your field names, so no mapping is needed.
Yes. Each series has a color picker, and the chartConfig in the copied code uses your colors. By default bars use your theme's --chart-1 to --chart-5 variables.
The shadcn/ui chart component (npx shadcn@latest add chart), which also brings in Recharts. The generated file has no other dependencies.