Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

Area Chart

PreviousNext

Change over time as filled areas, stacked or stretched to the whole, with a gliding crosshair and tooltip.

Monthly revenue
Acme Inc, this year against last
Monthly revenue
This yearLast year
Jan$36K$37K
Feb$43K$36K
Mar$44K$36K
Apr$44K$40K
May$49K$43K
Jun$52K$41K
Jul$54K$44K
Aug$59K$46K
Sep$64K$51K
Oct$67K$56K
Nov$72K$54K
Dec$76K$56K

Give it rows of data, the field that places each row along the bottom (index) and a config that names the series to draw. Each series is a line with a wash fading down under it, in the next colour of the chart palette. Point at the chart, drag a finger across it or tab to it and use the arrow keys: a crosshair finds the nearest row and a tooltip lists every series there. The legend hides a series when pressed and spotlights it when pointed at.

The areas draw in from the start edge the first time the chart is on screen, and morph to new values when the data changes. Area Chart is part of the Fabricator style. It's drawn in SVG, so the same component ships for every base, and its layout comes from the same model as the React Native version.

Installation

bunx --bun fabricator-ui@latest add area-chart

Usage

import { AreaChart } from "@/components/ui/area-chart"
import { type ChartConfig } from "@/components/ui/chart-kit"
const data = [
  { month: "Jan", thisYear: 36_400, lastYear: 36_500 },
  { month: "Feb", thisYear: 43_000, lastYear: 35_800 },
  { month: "Mar", thisYear: 43_900, lastYear: 36_300 },
]
 
const config = {
  thisYear: { label: "This year" },
  lastYear: { label: "Last year" },
} satisfies ChartConfig
 
<AreaChart data={data} index="month" config={config} label="Monthly revenue" />

Each key of config is a field of the rows. A missing or non-numeric value leaves a gap in the line. The chart fills its container's width and is 18rem tall until you give it a height with className.

Values print in full (1,234) until you pass formatValue. It also formats the hidden table, which renders on the server, so use a formatter that writes the same text in Node and in the browser: formatChartNumber(value, { compact: true }) from lib/chart-model gives 43.9K on both, where Intl's compact notation can differ between them.

Examples

Stacked

stack="stacked" sets each series on the ones before it, so the top line is the total. The tooltip still shows each series' own value.

Weekly visits by source
Organic searchDirectReferral
W14,2002,4001,100
W24,6002,3001,400
W34,1002,9001,300
W45,3003,1001,700
W55,9003,0002,100
W66,4003,6001,900
W76,1003,9002,400
W87,2004,1002,600

Expanded

stack="expand" stretches every row to the whole, so the chart reads as a mix rather than a size. The value axis counts to 100%, and the tooltip gives each value and its share.

Subscriptions by plan
StarterTeamEnterprise
Q1 2025420310120
Q2 2025460380150
Q3 2025430450210
Q4 2025400520260
Q1 2026380610330
Q2 2026350660410

Curves

curve is smooth (the default) for trends, linear when each reading matters, or step for values that hold until they change.

Requests per hour
Requests
08:00120
09:00340
10:00310
11:00460
12:00380
13:00520
14:00490
15:00610

Following the inspected row

onActiveChange reports the row under the pointer, the finger or the keyboard, and null when there is none, so a number above the chart can follow it. Switching the data morphs the areas to the new values.

Visitors on Sun
2,520
Visitors this week
DesktopMobile
Mon1,240980
Tue1,3801,120
Wed1,3101,260
Thu1,5201,190
Fri1,6901,430
Sat1,1201,610
Sun9801,540

Colours

Series take the chart palette in the order of config, and keep their colour when another is hidden. Give a series its own with color: a palette slot, an upstream chart token (chart-1 … chart-5), a role (primary, info, success, …), a CSS variable (var(--brand)) or any CSS colour.

TokenHueTokenHue
--chart-series-1blue--chart-series-5magenta
--chart-series-2orange--chart-series-6green
--chart-series-3aqua--chart-series-7violet
--chart-series-4amber--chart-series-8red

The palette ships with the foundations, chosen separately for light and dark. Every slot keeps 3:1 against the page and the card, and each colour stays apart from its neighbours for readers with red-green colour blindness. Slots never repeat: a ninth series is grey, so fold small series into an "Other" one before that.

Motion

  • Draw-in: the first time the chart scrolls into view, the areas sweep in from the start edge on the reveal role, once per mount.
  • Morph: when data, config, stack or the visible series change, each point moves to its new place on the move role. A series being shown grows from its baseline; one being hidden shrinks into it. Data with a different number of rows redraws instead.
  • Glide: the crosshair, dots and tooltip glide between rows on the glide role.

All three follow the motion speed of the region they sit in. Reduce Motion and the instant speed draw the chart at once and drop the glide; animate={false} does the same for one chart.

API Reference

AreaChart

All other props go to the root <div>.

PropTypeDefault
dataTDatum[]required
configChartConfigrequired
indexkeyof TDatumrequired
labelstringrequired: the accessible name
curve"smooth" | "linear" | "step""smooth"
stack"none" | "stacked" | "expand""none"
formatValue(value: number, key: string) => string1,234
formatIndex(value: string, datum: TDatum) => stringthe field as text
legendbooleanon for two or more series
tooltipbooleantrue
animatebooleantrue
loadingbooleanfalse
emptyReactNode"No data"
onActiveChange(active: ChartActive<TDatum> | null) => void-

ChartConfig

FieldTypeDefault
labelstringrequired
colorChartColorthe next palette slot
dashedbooleanfalse

Data attributes

AttributeElementPresent when
data-slot="area-chart"rootalways
data-loadingrootloading is true
data-slot="chart-plot"the plotalways
data-slot="chart-series"a seriesalways; data-dimmed while another is spotlit
data-slot="chart-legend"the legendthe legend shows
data-slot="chart-tooltip"the tooltipa row is inspected

Accessibility

  • The chart's plot is a slider named after label ("Monthly revenue: inspect values"). Tab to it, then Left and Right step through the rows, Home and End jump to the first and last, and Escape lets go. Its value text reads the tooltip: the row and every series' value.
  • Every value is also in a table hidden from sight, so a screen reader can read the data without inspecting it.
  • With two or more series the legend always shows, so no series is told apart by colour alone. Its items are toggle buttons with aria-pressed.
  • Text never takes a series colour: values and labels stay in the text colours, beside a coloured key.
  • loading sets aria-busy on the root and dims the last drawing until new data arrives.