Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Chart examples · Area

An area chart with gradient fill for React

A stacked area chart whose areas fade from the series color to transparent.

Framework
UI library

Gradient fills keep the area readable without a heavy block of color. Each series fills with an SVG linearGradient that fades from the series color at the top to nearly transparent at the bottom.

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 is the gradient defined?

Each series has a linearGradient in defs. Desktop's id is gradientFillDesktop, mobile's is gradientFillMobile. Both set x1="0", x2="0", y1="0", and y2="1", so the fade runs from the top of the area to the bottom.

What do the two stops do?

The first stop is offset="5%" with stopOpacity={0.8}. The second is offset="95%" with stopOpacity={0.1}. stopColor is var(--color-desktop) or var(--color-mobile), the same variables the strokes use.

How does the area use that gradient?

Area sets fill to url(#gradientFillDesktop) or url(#gradientFillMobile). It also sets fillOpacity={0.4}, which fades the whole gradient again. stroke stays the solid series color, and type is natural.

How do the two gradients stack?

Both areas set stackId="a". Mobile is first, on the baseline. Desktop is second, on top. Their colors come from config: mobile is var(--chart-2), desktop is var(--chart-1).

What does the tooltip show?

ChartTooltip renders ChartTooltipContent with no extra props, so the indicator stays a dot, and sets cursor={false}. The title is the month. The rows are Mobile and Desktop from config. The gradient is only the fill.

How are the months labeled?

XAxis uses dataKey="month" and tickFormatter={formatMonth}, which keeps value.slice(0, 3). CartesianGrid sets vertical={false}. AreaChart sets accessibilityLayer and a margin of left: 12 and right: 12.