Skip to main content
SidsProjectImpact

Back to all posts

How to Create A Stacked Area Chart In Chart.js?

Published on
4 min read
How to Create A Stacked Area Chart In Chart.js? image

Best Charting Tools to Buy in January 2026

1 The Microsoft Office 365 Bible: The Most Updated and Complete Guide to Excel, Word, PowerPoint, Outlook, OneNote, OneDrive, Teams, Access, and Publisher from Beginners to Advanced

The Microsoft Office 365 Bible: The Most Updated and Complete Guide to Excel, Word, PowerPoint, Outlook, OneNote, OneDrive, Teams, Access, and Publisher from Beginners to Advanced

BUY & SAVE
$32.97
The Microsoft Office 365 Bible: The Most Updated and Complete Guide to Excel, Word, PowerPoint, Outlook, OneNote, OneDrive, Teams, Access, and Publisher from Beginners to Advanced
2 Charting Made Easy

Charting Made Easy

  • QUALITY ASSURANCE: EACH BOOK CAREFULLY INSPECTED FOR READABILITY.
  • AFFORDABLE PRICING: SAVE MONEY ON YOUR FAVORITE READS TODAY!
  • ECO-FRIENDLY CHOICE: SUPPORT SUSTAINABILITY WITH PRE-LOVED BOOKS.
BUY & SAVE
$12.48 $40.00
Save 69%
Charting Made Easy
3 Pro Tools Perpetual License NEW 1-year software download with updates + support for a year

Pro Tools Perpetual License NEW 1-year software download with updates + support for a year

  • FULL PERMANENT LICENSE WITH 1 YEAR OF SOFTWARE UPDATES INCLUDED!
  • INDUSTRY-STANDARD TOOLS FOR HIGH-QUALITY MUSIC PRODUCTION ON ANY DEVICE.
  • OVER 60 VIRTUAL INSTRUMENTS AND EFFECTS TO ENHANCE YOUR SOUND!
BUY & SAVE
$599.00
Pro Tools Perpetual License NEW 1-year software download with updates + support for a year
4 Disruptive Analytics: Charting Your Strategy for Next-Generation Business Analytics

Disruptive Analytics: Charting Your Strategy for Next-Generation Business Analytics

BUY & SAVE
$27.53 $37.99
Save 28%
Disruptive Analytics: Charting Your Strategy for Next-Generation Business Analytics
5 Candlestick Charting For Dummies

Candlestick Charting For Dummies

BUY & SAVE
$18.00
Candlestick Charting For Dummies
6 Charting the Course: Coming up with Great Test Ideas; Just in Time

Charting the Course: Coming up with Great Test Ideas; Just in Time

BUY & SAVE
$13.99
Charting the Course: Coming up with Great Test Ideas; Just in Time
7 Charting Made Easy: 109 Ideas for Simplifying Complex Data

Charting Made Easy: 109 Ideas for Simplifying Complex Data

BUY & SAVE
$8.99
Charting Made Easy: 109 Ideas for Simplifying Complex Data
8 OrgChart Profession v6 50 Charting Limit [Download]

OrgChart Profession v6 50 Charting Limit [Download]

  • EFFORTLESSLY IMPORT DATA FROM EXCEL, ACCESS, ORACLE, AND MORE.
  • PUBLISH STUNNING CHARTS IN WORD, POWERPOINT, AND INTERACTIVE FORMATS.
  • SCALABLE SOLUTION FOR ANY BUSINESS, FROM 50 TO 50,000 CHARTS!
BUY & SAVE
$99.99
OrgChart Profession v6 50 Charting Limit [Download]
+
ONE MORE?

To create a stacked area chart in Chart.js, you will need to define multiple datasets that represent the different areas to be stacked on top of each other. Each dataset should have its own data array containing the values for each point on the x-axis.

You will also need to ensure that the "type" property of your chart configuration is set to "line" to create an area chart. Additionally, you can set the "fill" property of each dataset to "origin" to stack the areas on top of each other.

After defining your datasets and configuring your chart, you can create a new Chart object with the appropriate canvas element and configuration options. Finally, you can call the "update" method on your chart object to display the stacked area chart on the canvas.

How can I customize the colors of a stacked area chart in Chart.js?

To customize the colors of a stacked area chart in Chart.js, you can define an array of color values in the dataset options. Here's an example code snippet to demonstrate how you can set custom colors for each dataset in a stacked area chart:

var ctx = document.getElementById('myChart').getContext('2d');

var myChart = new Chart(ctx, { type: 'line', data: { labels: ['January', 'February', 'March', 'April', 'May'], datasets: [{ label: 'Dataset 1', data: [10, 20, 30, 40, 50], backgroundColor: 'rgba(255, 99, 132, 0.5)', // Custom color for Dataset 1 }, { label: 'Dataset 2', data: [20, 30, 40, 50, 60], backgroundColor: 'rgba(54, 162, 235, 0.5)', // Custom color for Dataset 2 }] }, options: { scales: { x: { stacked: true, }, y: { stacked: true } } } });

In this example, we specified custom colors using the backgroundColor property for each dataset in the datasets array. You can define colors either as a hex code (e.g., #FF5733) or an RGBA value (e.g., rgba(255, 99, 132, 0.5)).

You can further customize the styling of the stacked area chart by modifying other properties in the dataset or options objects, such as border color, border width, and other chart configurations.

How can I make a stacked area chart responsive in Chart.js?

To make a stacked area chart responsive in Chart.js, you can use the following steps:

  1. Set the responsive option in the chart configuration to true:

options: { responsive: true, maintainAspectRatio: false }

  1. Use a percentage width and height for the canvas element that contains the chart:

  1. Add the following CSS styles to ensure that the chart resizes with the container:

#myChart { width: 100%; height: 80%; }

By following these steps, you can create a responsive stacked area chart in Chart.js that will adjust its size based on the dimensions of the container it is placed in.

How to create a multi-series stacked area chart in Chart.js?

To create a multi-series stacked area chart in Chart.js, you will need to define multiple datasets in the configuration options of the chart. Each dataset will represent a different series in the stacked area chart. Here's a step-by-step guide on how to create a multi-series stacked area chart in Chart.js:

  1. First, include the Chart.js library in your HTML file:
  1. Create a canvas element in your HTML where you want the chart to be displayed:

  1. Initialize a new Chart.js chart in your JavaScript file and define the configuration options for the chart:

var ctx = document.getElementById('myChart').getContext('2d');

var chartData = { labels: ['January', 'February', 'March', 'April', 'May'], datasets: [ { label: 'Series 1', data: [10, 20, 15, 25, 30], backgroundColor: 'rgba(255, 99, 132, 0.2)' }, { label: 'Series 2', data: [5, 15, 10, 20, 25], backgroundColor: 'rgba(54, 162, 235, 0.2)' }, { label: 'Series 3', data: [8, 18, 13, 23, 28], backgroundColor: 'rgba(255, 206, 86, 0.2)' } ] };

var myChart = new Chart(ctx, { type: 'bar', data: chartData, options: { scales: { x: { stacked: true, }, y: { stacked: true } } } });

In this example, we have defined three datasets representing three different series in the stacked area chart. Each dataset has a label, data array, and backgroundColor property to specify the color of the area chart for that series.

  1. Customize the chart further by adding additional configuration options like legend, tooltips, and axis labels as needed.
  2. Finally, your multi-series stacked area chart should be displayed in the canvas element on your webpage.