shadcn.io is not affiliated with official shadcn/ui
About
Pick it for a dashboard's headline chart, where a flat tint feels heavy but the series should still read as shapes. It's the stacked area with a different paint: the data and the reading are the same. At small sizes or over dense grid lines, a flat fill stays clearer.
Each band fades from strong near its top to faint near the bottom, in its own color, under a solid edge. Mobile stacks under desktop, and the tooltip lists both with dots.
Installation
Usage
import { ChartAreaGradient } from "@/components/charts/chart-area-gradient";<ChartAreaGradient />Customize
<defs>inside<AreaChart>holds two<linearGradient>s,fillDesktopandfillMobile, fromstopOpacity={0.8}at 5% to0.1at 95%.- Each
<Area>setsfill="url(#fillDesktop)"(orfillMobile) and keepsstroke="var(--color-desktop)". - The stops'
stopColorreadsvar(--color-<key>), so the gradient followschartConfigand dark mode. - Gradient ids live in the page's DOM: rename them when two of these charts render together.
FAQ
How is the fade made?
With SVG: a <linearGradient> in <defs> with two <stop>s, and fill="url(#fillDesktop)" on the <Area>.
How do I fade all the way to transparent?
Set stopOpacity={0} on the 95% stop. The <Area> also has fillOpacity={0.4}, which multiplies with the stops; remove it to use their full range.
Do two gradient charts on one page clash?
They can. fillDesktop is an id in the page's DOM, so a second chart with the same ids may paint from the first chart's gradients. Give each chart its own ids, for example with useId().
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
Interactive Area Chart
Area chartsThree months of daily visitors with a time range select.
Stacked Area Chart
Area chartsTwo series stacked into one total, each band its own color.
Area Chart
Area chartsOne series as a smooth filled curve over six months.
Radial Chart with Custom Shape
Radial chartsA thick ring with a custom end angle and the total inside.
Multiple Bar Chart
Bar chartsTwo series grouped side by side for each month.
Expanded Stacked Area Chart
Area chartsStacked areas expanded to 100%, so each band reads as a share.