Stacked area charts

A line chart could be used to show how much CO2 that each country releases in the atmosphere each year. It would reveal if a country's emissions were increasing, stable, or decreasing, but such a line chart would not be very useful to show the total amount of CO2 released in the air, and how each country contributes to this total. You can display this kind of information using a stacked area chart.

There is no special area type chart in Chart.js. Instead, you can create a simple overlapping area chart configuring the fill properties for each dataset in a line chart. To create a stacked area chart, you will need to set the stacked property to true in the x and y-axes.

Let's try an example. We will use a JSON file containing ...

Get Learn Chart.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.