PeakUIPro

AreaChart

Area chart with gradient fills and stacked series

Usage

AreaChart is imported from its own subpath and needs the optional recharts peer.

npm install recharts
import {AreaChart} from "@peakui-pro/react/area-chart";

Anatomy

import {AreaChart} from "@peakui-pro/react/area-chart";

// Only the root is this package's own; the parts are the charting library's components under
// PeakUI names. The root is not exported from `@peakui-pro/react`, so an app that renders no
// chart never needs the peer installed, not even to render on a server.
export default () => (
  <AreaChart aria-label="Revenue by month" data={[]}>
    <AreaChart.Grid />
    <AreaChart.XAxis />
    <AreaChart.YAxis />
    <AreaChart.Area dataKey="revenue" />
    <AreaChart.Tooltip content={<AreaChart.TooltipContent />} />
  </AreaChart>
);

Accessibility

The plot takes focus and answers the arrow keys, so aria-label names it, not the wrapper.

// Named by a string, or by the element that already carries the metric's title.
<AreaChart aria-label="Revenue by month" data={data} />
<AreaChart aria-labelledby="revenue-title" data={data} />

Examples

Multi Area

Stacked

One stackId across the series: each area sits on the one below it.

Sparkline

Custom Tooltip

Customization

Tailwind CSS

<AreaChart className="rounded-xl bg-surface p-4" data={data} />

Global CSS

@layer components {
  .chart {
    --chart-axis-size: 11px;
    --chart-grid-opacity: 0.4;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The AreaChart component uses these CSS classes (view source styles):

Base Classes

  • .chart - The block every chart carries; axis type, grid, tooltip cursor and active dot
  • .area-chart - This chart's own block; the rounded joins of a series line

Slots

  • [data-slot="area-chart"] - The root element

CSS Variables

VariablePurpose
--chart-axis-sizeType size of the axis labels; set on .chart
--chart-grid-opacityHow far the grid recedes behind the data; set on .chart
--chart-1 … --chart-5The series ramp, derived from the theme's accent

API Reference

AreaChart

PropTypeDefaultDescription
dataRecord<string, number | string | null>[]-Required. One object per point on the x axis; a null field is a missing observation
heightnumber | `${number}%` 300Height of the plot
widthnumber | `${number}%` '100%'Width of the plot
margin{top?: number; right?: number; bottom?: number; left?: number}{top: 8, right: 8, bottom: 0, left: 0}Space between the plot and the root's edges
childrenReactNode-The chart's parts
aria-labelstring-Names the plot, which is what takes focus — not the wrapping <div>
aria-labelledbystring-Names the plot by another element's id
classNamestring-Additional classes
...restComponentProps<'div'>-Native <div> attributes, on the wrapper

AreaChart.Area

The charting library's Area, re-exported. See the Recharts Area API.

AreaChart.XAxis

The charting library's XAxis, re-exported. See the Recharts XAxis API.

AreaChart.YAxis

The charting library's YAxis, re-exported. See the Recharts YAxis API.

AreaChart.Grid

The charting library's CartesianGrid, re-exported. See the Recharts CartesianGrid API.

AreaChart.Tooltip

The charting library's Tooltip, re-exported. See the Recharts Tooltip API.

AreaChart.TooltipContent

ChartTooltip.Content, for the content prop of AreaChart.Tooltip. Its props are on the ChartTooltip page.

On this page