shadcn.io is not affiliated with official shadcn/ui
Chart examples · Area
An area chart with a legend for React
A stacked area chart of desktop and mobile visitors with a legend below it.
Use a legend once a chart has more than one series. Desktop and mobile are stacked areas, and ChartLegend names both with their colors under the chart.
Preview
Installation
FAQ
How does the legend get Desktop and Mobile?
ChartLegend sets content to ChartLegendContent. That reads label from config for each series and draws a color swatch. These entries have no icon, and this file passes no onClick. verticalAlign stays at bottom, which adds space above the legend.
How are the areas stacked under that legend?
Both Area components set stackId="a". Mobile is first, on the baseline. Desktop is second, on top. Both use type="natural" and fillOpacity={0.4}, and they fill var(--color-mobile) and var(--color-desktop).
How do I move the legend above the chart?
Set verticalAlign="top" on ChartLegend. ChartLegendContent then uses the top spacing, pb-3, under the legend. The default bottom uses pt-3 above it. The labels still come from config.
What does the tooltip show?
ChartTooltipContent sets indicator="line". The title is the month, and the rows are Mobile and Desktop with their values. cursor={false} on ChartTooltip turns the hover cursor off.
Related
- An area chart with iconsA stacked area chart whose legend and
- A simple area chartA single-series area chart with a smooth
- A stacked area chartAn area chart stacking desktop and mobile
- A multiple line chartA line chart comparing desktop and mobile
- A multiple bar chartA bar chart grouping desktop and mobile
- An interactive area chartA stacked area chart of three months of