shadcn.io is not affiliated with official shadcn/ui
About
Use it when the total matters and so does its split: traffic by device, revenue by plan, tickets by team. The top edge is the total; the boundary inside it is the split. For shares rather than amounts, use the expanded version. For series that don't add up to anything, use a multiple line chart.
Mobile sits at the bottom with desktop stacked on it, each a smooth curve with a 40% fill in its own color. Hovering a month lists both values with a dot beside each.
Installation
Usage
import { ChartAreaStacked } from "@/components/charts/chart-area-stacked";<ChartAreaStacked />Customize
- Two
<Area>elements sharestackId="a", which stacks them; the first,mobile, is the bottom band. - Each
<Area>setstype="natural",fillOpacity={0.4}and its ownvar(--color-<key>)forfillandstroke. <ChartTooltipContent indicator="dot" />lists both series for the hovered month;cursor={false}hides the hover cursor.- Recharts reports each series' own value in the tooltip, not the stacked height.
FAQ
How do I choose which series sits at the bottom?
The order of the <Area> elements that share stackId="a": the first one is drawn at the bottom. Move the desktop <Area> above the mobile one to swap them.
How do I stack a third series?
Add a third <Area> with the same stackId="a", its own dataKey and fill/stroke of var(--color-<key>), and a chartConfig entry for the key. Past two series, add a legend.
How do I show the total in the tooltip?
The tooltip lists one row per <Area>. For a total, pass ChartTooltipContent a formatter that adds a row after the last item, as the Advanced Tooltip chart does; each call gets the item and the whole data row.
Can the areas overlap instead of stacking?
Remove stackId from both <Area>s. Each then starts at zero and the later one draws over the first, so keep fillOpacity low.
API Reference
ChartContainer
configChartConfig
Each series by its data key: its label, an icon, and a color (or a * theme color per light and dark), read by the tooltip and legend and set * as --color-<key>.
initialDimension?{ height: number; width: number; }
The size it renders at before it's measured, so the first paint isn't * empty.
- Type
{ height: number; width: number; }- Default
INITIAL_DIMENSION
className?string
Merged with the part's classes.
ChartLegend
ChartLegendContent
<div>
hideIcon?boolean
Hides each series' icon (from config), leaving its color swatch.
- Default
false
nameKey?string
The key in each legend item's data to look its label up by in config. * Defaults to the item's dataKey.
className?string
Merged with the part's classes.
ChartStyle
<style>
configChartConfig
The chart config whose colors it writes as --color-<key> variables.
idstring
The element's id.
ChartTooltip
ChartTooltipContent
<div>
hideIndicator?boolean
Hides each item's color indicator.
- Default
false
hideLabel?boolean
Hides the tooltip's label, the hovered point's.
- Default
false
indicator?"dashed" | "dot" | "line"
The color indicator's shape: a dot, a line or dashed.
- Type
"dashed" | "dot" | "line"- Default
"dot"
labelFormatter?(label: any, payload: TooltipPayload) → React.ReactNode
Formats the tooltip's label; its value is untyped, as in recharts 3.8.
- Type
(label: any, payload: TooltipPayload) → React.ReactNode- Parameters
label– anypayload– TooltipPayload- Returns
React.ReactNode
labelKey?string
The key in the data to read the label from, looked up in config.
nameKey?string
The key in each item's data to look its name up by in config.
className?string
Merged with the part's classes.
Related
Expanded Stacked Area Chart
Area chartsStacked areas expanded to 100%, so each band reads as a share.
Area Chart with Legend
Area chartsStacked areas with a legend naming each series.
Gradient Area Chart
Area chartsAreas filled with a vertical gradient that fades to the axis.
Stacked Bar Chart with Legend
Bar chartsTwo series stacked in each bar, with a legend.
Multiple Line Chart
Line chartsTwo series as lines on the same axes.
Area Chart with Axes
Area chartsStacked areas with both axes and their tick labels drawn.