Skip to content
OpenChart

Area

Fill the space under a line to show how a quantity builds over time, then add reference lines and compare overlapping series from a shared zero baseline.

An area chart is a line with the space beneath it filled, so the reader sees the size of the quantity as well as its direction. It suits a running total or a magnitude that starts at zero, such as a fleet size or a cumulative count.

Use a line chart when you compare several series and the slopes are what matter. Use a stacked area when the series add up to a total and the parts are the point.

A basic area chart

Set mark to "area" with the same x and y channels a line uses. Passing the mark as an object lets you set stroke and strokeWidth for the outline. A text annotation with a connector marks the milestone.

201620182020202220240102030405060Cumulative EV fleet (millions)10M milestoneThe world's electric car fleet reached 58million in 2024Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)201620182020202220240102030405060Cumulative EV fleet (millions)10M milestoneThe world's electric car fleet reached 58million in 2024Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)
Cumulative electric car fleet. Source: IEA Global EV Outlook 2025.
{
  "mark": {
    "type": "area",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "data": [
    {
      "year": "2015-01-01",
      "fleet": 1.3
    },
    {
      "year": "2016-01-01",
      "fleet": 2.1
    },
    {
      "year": "2017-01-01",
      "fleet": 3.2
    },
    {
      "year": "2018-01-01",
      "fleet": 5.4
    },
    {
      "year": "2019-01-01",
      "fleet": 7.5
    },
    {
      "year": "2020-01-01",
      "fleet": 10.5
    },
    {
      "year": "2021-01-01",
      "fleet": 17.1
    },
    {
      "year": "2022-01-01",
      "fleet": 27
    },
    {
      "year": "2023-01-01",
      "fleet": 41
    },
    {
      "year": "2024-01-01",
      "fleet": 58
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 5
      }
    },
    "y": {
      "field": "fleet",
      "type": "quantitative",
      "axis": {
        "title": "Cumulative EV fleet (millions)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2020-01-01",
      "y": 10.5,
      "text": "10M milestone",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -22
      },
      "connector": true
    }
  ],
  "chrome": {
    "title": "The world's electric car fleet reached 58 million in 2024",
    "subtitle": "Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 5
      }
    },
    "y": {
      "field": "fleet",
      "type": "quantitative",
      "axis": {
        "title": "Cumulative EV fleet (millions)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2020-01-01",
      "y": 10.5,
      "text": "10M milestone",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -22
      },
      "connector": true
    }
  ],
  "chrome": {
    "title": "The world's electric car fleet reached 58 million in 2024",
    "subtitle": "Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 5
      }
    },
    "y": {
      "field": "fleet",
      "type": "quantitative",
      "axis": {
        "title": "Cumulative EV fleet (millions)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2020-01-01",
      "y": 10.5,
      "text": "10M milestone",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -22
      },
      "connector": true
    }
  ],
  "chrome": {
    "title": "The world's electric car fleet reached 58 million in 2024",
    "subtitle": "Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 5
      }
    },
    "y": {
      "field": "fleet",
      "type": "quantitative",
      "axis": {
        "title": "Cumulative EV fleet (millions)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2020-01-01",
      "y": 10.5,
      "text": "10M milestone",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -22
      },
      "connector": true
    }
  ],
  "chrome": {
    "title": "The world's electric car fleet reached 58 million in 2024",
    "subtitle": "Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 5
      }
    },
    "y": {
      "field": "fleet",
      "type": "quantitative",
      "axis": {
        "title": "Cumulative EV fleet (millions)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2020-01-01",
      "y": 10.5,
      "text": "10M milestone",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -22
      },
      "connector": true
    }
  ],
  "chrome": {
    "title": "The world's electric car fleet reached 58 million in 2024",
    "subtitle": "Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Reference values

A refline annotation draws a horizontal rule at a value in data units, and its label names it. Here a dashed rule at $100 shows when the price crossed that level. The y axis starts at zero, so the filled height is proportional to the value.

202320242025050100150200Closing price ($)$100Nvidia's price crossed $100 in 2024Split-adjusted monthly close, January 2023 to December 2025202320242025050100150200Closing price ($)$100Nvidia's price crossed $100 in 2024Split-adjusted monthly close, January 2023 to December 2025
Nvidia monthly closing price. Source: Nasdaq historical data.
{
  "mark": {
    "type": "area",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "data": [
    {
      "date": "2023-01-01",
      "price": 19.52
    },
    {
      "date": "2023-02-01",
      "price": 23.19
    },
    {
      "date": "2023-03-01",
      "price": 27.75
    },
    {
      "date": "2023-04-01",
      "price": 27.73
    },
    {
      "date": "2023-05-01",
      "price": 37.8
    },
    {
      "date": "2023-06-01",
      "price": 42.27
    },
    // … 30 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "price",
      "type": "quantitative",
      "axis": {
        "title": "Closing price ($)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "refline",
      "y": 100,
      "label": "$100",
      "style": "dashed",
      "stroke": "#64748b",
      "strokeWidth": 1
    }
  ],
  "chrome": {
    "title": "Nvidia's price crossed $100 in 2024",
    "subtitle": "Split-adjusted monthly close, January 2023 to December 2025"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 36 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "price",
      "type": "quantitative",
      "axis": {
        "title": "Closing price ($)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "refline",
      "y": 100,
      "label": "$100",
      "style": "dashed",
      "stroke": "#64748b",
      "strokeWidth": 1
    }
  ],
  "chrome": {
    "title": "Nvidia's price crossed $100 in 2024",
    "subtitle": "Split-adjusted monthly close, January 2023 to December 2025"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 36 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "price",
      "type": "quantitative",
      "axis": {
        "title": "Closing price ($)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "refline",
      "y": 100,
      "label": "$100",
      "style": "dashed",
      "stroke": "#64748b",
      "strokeWidth": 1
    }
  ],
  "chrome": {
    "title": "Nvidia's price crossed $100 in 2024",
    "subtitle": "Split-adjusted monthly close, January 2023 to December 2025"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 36 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "price",
      "type": "quantitative",
      "axis": {
        "title": "Closing price ($)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "refline",
      "y": 100,
      "label": "$100",
      "style": "dashed",
      "stroke": "#64748b",
      "strokeWidth": 1
    }
  ],
  "chrome": {
    "title": "Nvidia's price crossed $100 in 2024",
    "subtitle": "Split-adjusted monthly close, January 2023 to December 2025"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 36 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "price",
      "type": "quantitative",
      "axis": {
        "title": "Closing price ($)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "refline",
      "y": 100,
      "label": "$100",
      "style": "dashed",
      "stroke": "#64748b",
      "strokeWidth": 1
    }
  ],
  "chrome": {
    "title": "Nvidia's price crossed $100 in 2024",
    "subtitle": "Split-adjusted monthly close, January 2023 to December 2025"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Overlapping series

Multi-series areas stack by default. Setting stack: null on the y channel draws each series from the same zero baseline instead, with translucent fills, so you can compare the series with each other. The mode is for comparison rather than composition.

2019202020212022202320240100200300400500600Annual revenue ($B)Amazon638Alphabet350Meta164Each company's revenue is drawn from the samezero lineAnnual revenue by company, 2019-2024 (billions USD)2019202020212022202320240100200300400500600Annual revenue ($B)Amazon638Alphabet350Meta164Each company's revenue is drawn from the samezero lineAnnual revenue by company, 2019-2024 (billions USD)
Revenue of three companies, overlapping. Source: Company annual reports (SEC 10-K filings).
{
  "mark": "area",
  "data": [
    {
      "year": "2019-01-01",
      "revenue": 280,
      "company": "Amazon"
    },
    {
      "year": "2020-01-01",
      "revenue": 386,
      "company": "Amazon"
    },
    {
      "year": "2021-01-01",
      "revenue": 470,
      "company": "Amazon"
    },
    {
      "year": "2022-01-01",
      "revenue": 514,
      "company": "Amazon"
    },
    {
      "year": "2023-01-01",
      "revenue": 574,
      "company": "Amazon"
    },
    {
      "year": "2024-01-01",
      "revenue": 638,
      "company": "Amazon"
    },
    // … 12 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "revenue",
      "type": "quantitative",
      "stack": null,
      "axis": {
        "title": "Annual revenue ($B)",
        "format": ",.0f",
        "grid": true
      }
    },
    "color": {
      "field": "company",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Each company's revenue is drawn from the same zero line",
    "subtitle": "Annual revenue by company, 2019-2024 (billions USD)"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 18 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "area",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "revenue",
      "type": "quantitative",
      "stack": null,
      "axis": {
        "title": "Annual revenue ($B)",
        "format": ",.0f",
        "grid": true
      }
    },
    "color": {
      "field": "company",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Each company's revenue is drawn from the same zero line",
    "subtitle": "Annual revenue by company, 2019-2024 (billions USD)"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 18 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "area",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "revenue",
      "type": "quantitative",
      "stack": null,
      "axis": {
        "title": "Annual revenue ($B)",
        "format": ",.0f",
        "grid": true
      }
    },
    "color": {
      "field": "company",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Each company's revenue is drawn from the same zero line",
    "subtitle": "Annual revenue by company, 2019-2024 (billions USD)"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 18 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "area",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "revenue",
      "type": "quantitative",
      "stack": null,
      "axis": {
        "title": "Annual revenue ($B)",
        "format": ",.0f",
        "grid": true
      }
    },
    "color": {
      "field": "company",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Each company's revenue is drawn from the same zero line",
    "subtitle": "Annual revenue by company, 2019-2024 (billions USD)"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 18 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "area",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "revenue",
      "type": "quantitative",
      "stack": null,
      "axis": {
        "title": "Annual revenue ($B)",
        "format": ",.0f",
        "grid": true
      }
    },
    "color": {
      "field": "company",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Each company's revenue is drawn from the same zero line",
    "subtitle": "Annual revenue by company, 2019-2024 (billions USD)"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Fields that matter

Field What it does
mark "area", or an object such as { type: "area", stroke: "#0e7490", strokeWidth: 2 } to style the outline.
encoding.x The horizontal position, usually type: "temporal".
encoding.y The value that sets the height of the fill.
encoding.y.stack null overlaps series on a shared baseline. Without it, multiple series stack.
encoding.color One area per value of this field.
annotations text and refline marks placed in data coordinates.
  • Line for slopes and several series.
  • Stacked area for parts of a total over time.
  • Sparkline for an area drawn small.
  • Histogram for the shape of a distribution rather than change over time.
  • Marks reference lists the channels and options each mark type takes.