shadcn.io is not affiliated with official shadcn/ui
Chart examples · Area
An area chart with icons for React
A stacked area chart whose legend and tooltip show an icon for each series.
Use icons when color alone shouldn't tell the series apart. Each series in the chart config has an icon, which the legend draws beside its label in place of the color swatch.
Preview
Installation
FAQ
How do the icons get into the legend?
Set icon on the config entry. Desktop uses TrendingDownIcon and mobile uses TrendingUpIcon, beside the labels Desktop and Mobile. ChartLegendContent renders that component in place of the color swatch, at size-3.
Do the icons use the series color?
No. Legend icons paint with text-muted-foreground. The series color stays on the area: fill and stroke are var(--color-desktop) and var(--color-mobile), from var(--chart-1) and var(--chart-2) in config.
Does the tooltip show the icons too?
Yes. ChartTooltipContent draws the same icon on each row, so the color indicator is skipped for these series. This demo still sets indicator="line", which applies when an entry has no icon. cursor={false} turns the hover cursor off.
How are the areas stacked?
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}.
Related
- An area chart with a legendA stacked area chart of desktop and
- A simple area chartA single-series area chart with a smooth
- A line chartA line chart drawing one series as a
- A radar chart with iconsA radar chart whose legend shows an icon
- A bar chartA bar chart with rounded corners
- Accordion with Category IconsAn accordion of workspace sections, each