Area chart
Stacked or layered areas with a crosshair, soft edges and an entrance sweep.
Jan to Aug. Revenue: first $3,200, last $8,100, low $3,200, high $8,100. Cost: first $1,800, last $3,600, low $1,800, high $3,600.
| month | Revenue | Cost |
|---|---|---|
| Jan | $3,200 | $1,800 |
| Feb | $4,100 | $2,100 |
| Mar | $3,800 | $2,400 |
| Apr | $5,300 | $2,600 |
| May | $6,100 | $3,000 |
| Jun | $7,200 | $3,300 |
| Jul | $6,900 | $3,100 |
| Aug | $8,100 | $3,600 |
Installation
pnpm add @heyramzi/uiUsage
import { AreaChart } from "@heyramzi/ui/charts";<AreaChart
data={[{ month: "Jan", revenue: 3200, cost: 1800 }]}
xKey="month"
series={[
{ key: "revenue", label: "Revenue", color: "var(--chart-1)" },
{ key: "cost", label: "Cost", color: "var(--chart-3)" },
]}
height={260}
/>Examples
Two value axes
Set axis: "right" on a series to give it its own scale on the right. Both axes share one grid, each axis takes its series' colour, and the tooltip shows every series for the hovered day.
Oct 6 to Nov 2. Clicks: first 112, last 143, low 87, high 166. Impressions: first 4,410, last 5,330, low 3,710, high 6,030.
| date | Clicks | Impressions |
|---|---|---|
| Oct 6 | 112 | 4,410 |
| Oct 7 | 128 | 4,890 |
| Oct 8 | 141 | 5,230 |
| Oct 9 | 136 | 5,120 |
| Oct 10 | 98 | 3,980 |
| Oct 11 | 87 | 3,710 |
| Oct 12 | 119 | 4,620 |
| Oct 13 | 133 | 5,010 |
| Oct 14 | 152 | 5,540 |
| Oct 15 | 147 | 5,390 |
| Oct 16 | 158 | 5,810 |
| Oct 17 | 104 | 4,170 |
| Oct 18 | 96 | 3,920 |
| Oct 19 | 131 | 4,980 |
| Oct 20 | 144 | 5,360 |
| Oct 21 | 139 | 5,240 |
| Oct 22 | 161 | 5,920 |
| Oct 23 | 155 | 5,710 |
| Oct 24 | 109 | 4,300 |
| Oct 25 | 101 | 4,060 |
| Oct 26 | 138 | 5,150 |
| Oct 27 | 149 | 5,480 |
| Oct 28 | 157 | 5,770 |
| Oct 29 | 166 | 6,030 |
| Oct 30 | 151 | 5,600 |
| Oct 31 | 112 | 4,420 |
| Nov 1 | 107 | 4,210 |
| Nov 2 | 143 | 5,330 |
Keyboard and accessibility
| Key | Does |
|---|---|
| Tab | Moves focus to the plot. |
| Arrow Right Arrow Down | Shows the next point's tooltip. |
| Arrow Left Arrow Up | Shows the previous point's tooltip. |
| Home End | Shows the first or last point. |
| Esc | Hides the tooltip. |
- The plot is named by label, "Area chart" by default. A summary follows the name: the range, then each series' first, last, low and high value.
- The keys read out the point they land on and show the same tooltip as hover.
- A hidden table lists every point for a screen reader to browse.
- With reduced motion on, the area draws in place without the reveal.
API reference
datarequiredTData[]xKeyrequiredkeyof TData & stringyKeykeyof TData & stringseriesSeries[]colorstring- Default
"var(--chart-series-1)" heightnumber- Default
240 stackedboolean- Default
false smoothboolean- Default
true edgeFadeboolean | number- Default
true - Softens the left and right ends of the filled area instead of cutting them off at the plot edge.
formatValue(v: number) => string- Default
(v) => v.toLocaleString() formatX(v: unknown) => string- Default
(v) => String(v) xTicksnumber- Default
6 referenceChartReference- A target drawn across the plot, like the deal a cost runs up to.
resting{ value?: number; values?: Partial<Record<keyof TData & string, number>>; label: string; }- The headline while no point is hovered, like a period total. Defaults to the last point. `values`, keyed by series, shows one figure per series side by side in its colour, so it also reads as the legend.
smoothingSmoothing- Smooths the drawn line by the window shown; the resting figure stays the caller's total.
labelstring- Default
"Area chart" - The chart's accessible name. Its data range and values are read after it.
classstring
| Prop | Type | Default |
|---|---|---|
data required | TData[] | |
xKey required | keyof TData & string | |
yKey | keyof TData & string | |
series | Series[] | |
color | string | "var(--chart-series-1)" |
height | number | 240 |
stacked | boolean | false |
smooth | boolean | true |
edgeFade Softens the left and right ends of the filled area instead of cutting them off at the plot edge. | boolean | number | true |
formatValue | (v: number) => string | (v) => v.toLocaleString() |
formatX | (v: unknown) => string | (v) => String(v) |
xTicks | number | 6 |
reference A target drawn across the plot, like the deal a cost runs up to. | ChartReference | |
resting The headline while no point is hovered, like a period total. Defaults to the last point. `values`, keyed by series, shows one figure per series side by side in its colour, so it also reads as the legend. | { value?: number; values?: Partial<Record<keyof TData & string, number>>; label: string; } | |
smoothing Smooths the drawn line by the window shown; the resting figure stays the caller's total. | Smoothing | |
label The chart's accessible name. Its data range and values are read after it. | string | "Area chart" |
class | string |