shadcn.io is not affiliated with official shadcn/ui
Chart examples · Bar
A stacked bar chart with a legend for React
A bar chart stacking desktop and mobile visitors for each month, with a legend.
Use it to show each month's total and what it's made of. Desktop and mobile are stacked in one bar per month, the corners are rounded only on the outer ends, and a legend names both series.
Preview
Installation
FAQ
How do the bars stack?
Both Bar components set stackId="a". Desktop is first, so it sits on the baseline. Mobile is second, so it sits on top. The top of the mobile segment is that month's total. Each chartData row has desktop and mobile.
Why are the rounded corners split across the two bars?
Desktop sets radius={[0, 0, 4, 4]}, the bottom two corners. Mobile sets radius={[4, 4, 0, 0]}, the top two corners. The corners that meet in the middle stay square. Fills are var(--color-desktop) and var(--color-mobile).
How does the legend get its labels?
ChartLegend sets content to ChartLegendContent, which lists Desktop and Mobile from config, each with a color swatch. This file passes no onClick. verticalAlign stays at the default, bottom, which adds space above the legend.
What does the tooltip show?
ChartTooltipContent sets hideLabel, so the month isn't repeated in the title. The rows are Desktop and Mobile with their values. This ChartTooltip doesn't set cursor={false}, so the hovered bar keeps the default cursor.
Related
- A multiple bar chartA bar chart grouping desktop and mobile
- A bar chartA bar chart with rounded corners
- A stacked area chartAn area chart stacking desktop and mobile
- A stacked area chart with expand stackingA 100% stacked area chart showing each
- A horizontal bar chartA bar chart laid out horizontally, with
- A simple pie chartA pie chart of visitors by browser, each