Skip to content

React Area Chart

An animated React area chart with soft gradient fills, a crosshair tooltip and keyboard reading. Each row of readonly ChartRow[] is one x value; every series key holds a number, and its fill runs down to the zero baseline.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/line-chart.json

Visits per month

Use left and right arrow keys to read values.

Area chart with a gradient fill

The fill fades to transparent. Drag across the chart or use the arrow keys to read a month.

Visits per month

Sessions across the site

Files to copy

11 folders · 28 files · 4 packages
From theme/src/
  • components/charts/{line-chart.tsx, chart-annotations.tsx, chart-brush.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-sync.tsx, chart-utils.ts}
  • components/charts/chart-parts/
  • components/drawer/parts/sheet.tsx
  • components/kbd/
  • components/menu/
  • components/skeleton/
  • components/status-icons/
  • hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/line-chart.jsonRegistry item: line-chart. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".

AreaChart props

PropTypeDefaultDescription
data (required)readonly ChartRow[]NoneOne object per point: the index key plus one number per series key, e.g. { month: "Jan", visits: 4200 }.
classNamestringNoneAdds extra classes to the outer element.
aria-label (required)stringNoneAccessible summary of what the chart shows.
heightnumber260Height of the chart in px; the width follows the container.
format((n: number) => string)NoneFormat values in the tooltip, labels and on the axis. Without it, values use formatCompact (or the locale's compact format) and axis ticks get exactly as many decimals as their step needs.
labelsPartial<LineChartLabels>defaultLineChartLabelsThe chart's built-in strings (empty state, table text); a partial object over the English defaults, so pass only the keys you translate. Every other string, for translation: labels={{ instructions: "…" }}; omitted keys keep the English of defaultLineChartLabels. All 3 keys of LineChartLabels are listed in the key table under the props table.
localestringNoneLocale for the default number format (e.g. "de").
index (required)stringNoneKey of the x-axis value in each row (e.g. "month").
series (required)readonly CompareSeries[]NoneThe lines. color is a palette slot 1–8. Give a series a compareKey to draw its previous period from that key of each row as a dashed, muted line.
emptyStateReactNodeNoneShown when there is nothing to plot.
patternsbooleantrue when series.length > 3Tell series apart without colour: each series gets its own marker shape (circle, square, triangle, diamond).
gradientbooleantrueArea fill fades from the line to transparent (default). false: a flat soft wash.
glowbooleantrueSoft glow on the active line and point in dark mode.
hiddenSeriesreadonly string[]NoneSeries keys to hide (controlled). Inside a ChartCard the card's legend controls this.
highlightedSeriesstring | nullNoneSeries key to emphasise (the others dim). Inside a ChartCard, legend hover controls this.
annotationsreadonly ChartAnnotation[]NoneReference lines and bands, event markers and ranges.
syncbooleantrueInside a ChartSyncProvider: share the crosshair with the other charts.
tooltipSurfaceTooltipSurface"glass"Tooltip surface: "glass" (default) or "opaque" for busy charts.
endLabelsbooleantrueLabel the end of each line (only when labels don't collide; the legend always carries identity).
curveChartCurve"monotone""monotone" (default): smooth curves that never overshoot a value. "linear": straight segments.
zerobooleantrueKeep zero on the value axis (default). false fits the axis to the data, for values that live far from zero (rates, prices, temperatures). Areas then fill to the bottom of the plot.
brushboolean | LineChartBrushNoneA range selector under the chart for long series (drag, keyboard, touch).
liveboolean | { duration?: number; }off; an object's duration defaults to 0.6 inside the slide hookStreaming data: when the rows slide by (oldest out, newest in), the lines slide left instead of morphing. Pair with useLiveData(). duration = seconds per slide (default 0.6).
LineChartLabels keys and English defaults (3)
Pass any key in labels; the rest keep the defaults of defaultLineChartLabels.
KeyEnglish default
instructionsUse left and right arrow keys to read values.
previous(label) => `${label} (previous)`
brushnested object: takes the keys of ChartBrushLabels; empty here, so its own English defaults apply

When to use an area chart

A React area chart suits totals that accumulate or fill a range, such as traffic, storage used or active users. The gradient adds weight to the line without hiding the grid, which makes one or two series look calm and readable on a glass card.

When you need several series, the stacked area chart and the range area chart keep them readable. For plain trends compare the React line chart, and for tiny inline trends use a sparkline.

How the fill behaves

The fill is drawn once per series from the line down to the baseline and fades with the gradient, so a lone series reads as a soft silhouette of its own total. Two overlapping series show through each other where the lower one is the smaller, but the upper fill hides the lower line where it is the larger, so keep to one or two series and let the legend toggle the rest off.

The line on top of the fill keeps the same crosshair and point markers as the line chart, so reading a month never depends on the shading. Because the fill grows from the baseline, a truncated value axis makes a small change look like a large block of colour: leave zero on unless the title says the axis is cut.

Frequently asked questions

Keyboard

KeysAction
TabMove through the Chart / Table tabs, then the legend keys, then the chart itself.
← → (↑ ↓)Read the previous or next point; the values are announced.
Home/EndJump to the first or last point.
EscapeClear the active point.
Enter/Spaceon a legend keyHide or show that series.

Accessibility

  • Tab focuses the chart as one stop; the arrow keys read each point and announce every series value at it.
  • The Chart / Table tabs give the same numbers as a LineTable, so no value depends on the gradient fill, which is decoration.
  • The brush under a long series is its own tab stop: arrows, Page Up and Page Down, Home and End move the range.
  • Reduced motion: the fill and line appear at once and data changes jump.

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .