Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Chart examples · Area

A stacked area chart for React

An area chart stacking desktop and mobile visitors so its top edge shows the monthly total.

Framework
UI library

Use it when both the parts and the total matter. Desktop and mobile share a stackId, so mobile sits on the baseline, desktop on top of it, and the top edge traces the monthly total.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How do the two areas stack?

Both Area components set stackId="a". Mobile is first, so it sits on the baseline. Desktop is second, so it sits on top of mobile. The top edge of the desktop band is the month's total. Each row in chartData has both mobile and desktop.

How is each band colored?

Mobile fills and strokes var(--color-mobile). Desktop fills and strokes var(--color-desktop). Both set fillOpacity={0.4} and type="natural". config maps the keys to var(--chart-2) and var(--chart-1), with the labels Mobile and Desktop.

What does the tooltip show for a month?

ChartTooltipContent sets indicator="dot". The title is the month, and the rows are Mobile and Desktop from config, each with its own value. cursor={false} on ChartTooltip turns the hover cursor off.

How are the month labels shortened?

XAxis uses dataKey="month" and tickFormatter={formatMonth}, which returns value.slice(0, 3). axisLine and tickLine are false, and tickMargin is 8. CartesianGrid sets vertical={false}.

Can I reach a point from the keyboard?

Yes. AreaChart sets accessibilityLayer, so the plotted points can take focus. The month tick and the series labels in config name each point. The margin is left: 12 and right: 12.

How tall is the chart?

ChartContainer has no size class, so it keeps the default 16:9 box. The frame is w-full max-w-xl. There is no ChartLegend in this file. The series names are in the tooltip.