Area Chart
The Area Chart renders filled areas beneath lines, making it easy to compare cumulative totals or show how individual series contribute to a whole. It supports stacked mode (areas stacked on top of each other), per-series opacity and line interpolation, and includes crosshair, grid, tooltips, and a legend. On entry the area is revealed left-to-right as the line draws on, and it transitions smoothly between data states on update.
NOTE
For the full API, see the Charts API Reference.
Example
Usage
ts
import {
createAreaChart,
} from '@ripl/charts';
const chart = createAreaChart('#container', {
data: [/* ... */],
key: 'month',
stacked: false,
series: [
{ id: 'desktop', value: 'desktop', label: 'Desktop' },
{ id: 'mobile', value: 'mobile', label: 'Mobile' },
],
});Data Format
Each item should contain a key field and one or more numeric value fields:
ts
const data = [
{ month: 'Jan',
desktop: 620,
mobile: 340 },
{ month: 'Feb',
desktop: 780,
mobile: 290 },
{ month: 'Mar',
desktop: 550,
mobile: 410 },
];Variants
Stacked
Stack series to show cumulative totals:
ts
createAreaChart('#container', {
data,
key: 'month',
stacked: true,
series: [
{ id: 'desktop',
value: 'desktop',
label: 'Desktop',
opacity: 0.4 },
{ id: 'mobile',
value: 'mobile',
label: 'Mobile',
opacity: 0.4 },
],
});Custom opacity and line type
ts
createAreaChart('#container', {
data,
key: 'month',
series: [
{ id: 'desktop',
value: 'desktop',
label: 'Desktop',
opacity: 0.2,
lineType: 'monotoneX' },
{ id: 'mobile',
value: 'mobile',
label: 'Mobile',
opacity: 0.6,
lineType: 'step' },
],
});Options
data— The data arrayseries— Array of series withid,value,label, optionalcolor,opacity,lineType,lineStyle('solid'|'dashed'|'dotted'| custom dash array),lineWidth,markerskey— Key accessor for data pointsstacked— Stack series on top of each other (defaultfalse)grid—boolean | ChartGridOptions— Show/configure grid lines (defaulttrue)crosshair—boolean | ChartCrosshairOptions— Show/configure crosshair (defaulttrue)tooltip—boolean | ChartTooltipOptions— Show/configure tooltips (defaulttrue)legend—boolean | ChartLegendOptions— Show/configure legendaxis—boolean | ChartAxisOptions— Configure x/y axes