Stacked Bar Chart
NewBreakdowns over time as stacked totals or shares of 100%, with tooltips and a clickable legend.
Accounts by plan
| Bar | Free | Pro | Team |
|---|---|---|---|
| Jun | 820 | 310 | 90 |
| Jul | 900 | 360 | 110 |
| Aug | 860 | 420 | 150 |
| Sep | 980 | 470 | 170 |
| Oct | 1,040 | 560 | 220 |
| Nov | 1,120 | 640 | 260 |
Installation
$ pnpm dlx shadcn@latest add @synccn/stacked-bar-chartFirst time in this project? Connect synccn with one command.
Usage
import { StackedBarChart } from "@/components/ui/stacked-bar-chart";<StackedBarChart data={months} series={plans} />API reference
Generated from the component's TypeScript types, so it always matches the code.
StackedBarChart
Stacked bars for breakdowns over time (plan mix, traffic by source), as totals or as shares of 100%. Hover a bar for its numbers; click legend items to hide a series.
- datarequired
({ label: string } & Record<string, number | string>)[]One entry per bar: a label plus a value for each series key.
- seriesrequired
StackedBarSeries[]—
- height
numberDefault
240Height in pixels.
- format
(value: number) => stringDefault
(v) => v.toLocaleString("en-US")Formats values on the axis and in the tooltip.
- percent
booleanDefault
falseShows each bar as shares of 100%.
- className
stringExtra classes for the root element.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
Accessibility
- A visually hidden table holds every value. Legend items are toggle buttons with aria-pressed.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: img
- ARIA attributes: aria-labelledby, aria-pressed
- Includes text only screen readers hear