{"id":10634,"date":"2020-06-10T00:00:34","date_gmt":"2020-06-10T00:00:34","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=10634"},"modified":"2022-08-13T10:59:48","modified_gmt":"2022-08-13T10:59:48","slug":"stacked-area-chart-javascript-tutorial","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/","title":{"rendered":"How to Create Stacked Area Chart with JavaScript"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone size-full wp-image-10672\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial.png\" alt=\"JS stacked area chart and percent stacked area JS chart visualizing key COVID-19 data for Italy over time\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial.png 1700w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial-300x169.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial-768x432.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial-1024x576.png 1024w\" sizes=\"(max-width: 1700px) 100vw, 1700px\" \/><a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/stacked-area-chart\/\">Stacked area charts<\/a>,\u00a0a variation of classic <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/area-chart\/\">area charts<\/a>, are quite a popular form of data visualization.\u00a0They\u00a0work\u00a0great to\u00a0graphically represent how\u00a0multiple\u00a0variables\u00a0and their totals are <a href=\"https:\/\/www.anychart.com\/chartopedia\/usage-type\/chart-to-show-data-over-time\/\">changing over time<\/a>. In this tutorial, I will show you how to easily create\u00a0an interactive JavaScript stacked area chart\u00a0which will\u00a0look compelling\u00a0in any HTML5 project, web site or app.<\/p>\n<p>To demonstrate this way, which is\u00a0quite simple to master even if you only have basic HTML\u00a0coding skills,\u00a0I am going to visualize official data about the outbreak of the <a href=\"https:\/\/www.anychart.com\/blog\/tag\/covid-19\/\">COVID-19<\/a> pandemic in Italy. The visualizations built along the tutorial will\u00a0display how the\u00a0numbers of cases, recoveries, and deaths have been\u00a0changing \u2014 from\u00a0January 31, when the first two cases were confirmed, to yesterday, June 9, when the total number of coronavirus cases\u00a0in Italy reached\u00a0235,561.<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>4\u00a0Steps to Build JS Stacked Area Charts<\/h2>\n<p>The\u00a0development of any JavaScript graph, including a stacked area chart, can be broken down into the following four fundamental steps:<\/p>\n<ol>\n<li>Create\u00a0an HTML page for\u00a0the chart.<\/li>\n<li>Add necessary JavaScript files.<\/li>\n<li>Set the\u00a0data.<\/li>\n<li>Write the JS code for the chart.<\/li>\n<\/ol>\n<p>Let&#8217;s start with making a basic, value-based JS stacked area chart. Then I will show you how to customize it to suit your own needs and tasks. The final data visualization example will be the following JavaScript percent stacked area chart:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-10673\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/js-stacked-area-chart-javascript-html5.gif\" alt=\"Animated demonstration of the JavaScript stacked area chart (percentage-based) to be created along this tutorial\" width=\"100%\" \/><\/p>\n<p>Now, let\u2019s get down to\u00a0business!<\/p>\n<h3>Step 1: Create an HTML page<\/h3>\n<p>Begin\u00a0with creating a basic HTML page. This page should contain the following:<\/p>\n<ol>\n<li>A relevant title.<\/li>\n<li>An HTML block element (for example, <code>&lt;div&gt;<\/code>) which will\u00a0store your chart.<\/li>\n<li>An id attribute for the <code>&lt;div&gt;<\/code> (for example, \u201ccontainer\u201d).<\/li>\n<\/ol>\n<p>Note that you can also add CSS rules in the <code>&lt;style&gt;<\/code> block to modify the space that your stacked area chart will occupy. If you want\u00a0the graphic to fill the whole page, use 100% for both the <code>width<\/code> and <code>height<\/code> parameters.<\/p>\n<p>The HTML page should look like this:<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n  &lt;title&gt;Stacked Area Chart&lt;\/title&gt;\r\n  &lt;style&gt;\r\n    html,\r\n    body,\r\n    #container {\r\n      width: 100%;\r\n      height: 100%;\r\n      margin: 0;\r\n      padding: 0;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>Step 2: Add necessary JavaScript files<\/h3>\n<p>Now, you should reference all the necessary JS files in the <code>&lt;head&gt;<\/code> section.<\/p>\n<p>The stacked area chart that I will show you in this tutorial is based on <a href=\"https:\/\/www.anychart.com\">AnyChart<\/a>&#8216;s JS library. Generally, JavaScript libraries enable you to produce the desired output more quickly and easily. AnyChart is lightweight and flexible, so you can be as creative as you want and come up with a fully functional and responsive chart to use on your website or app.<\/p>\n<p>For this\u00a0charting tutorial, I will include the corresponding <a href=\"https:\/\/cdn.anychart.com\" target=\"_blank\" rel=\"nofollow\">CDN<\/a> links. If you prefer, you can download the scripts locally.<\/p>\n<p>The AnyChart JavaScript library features a modular system which is helpful in optimizing the size of the JS code running on a web page.\u00a0To make\u00a0a stacked area chart using it, add\u00a0two\u00a0<a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules\" target=\"_blank\" rel=\"nofollow\">modules:<\/a>\u00a0Core and Basic Cartesian. The first one is the basic AnyChart module required to use any other module.\u00a0The second\u00a0module\u00a0powers all Cartesian charts.<\/p>\n<p>Here is the HTML code for what we&#8217;ve got so far:<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n  &lt;title&gt;\r\nStacked Area Chart&lt;\/title&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-cartesian.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;style&gt;\r\n    html,\r\n    body,\r\n    #container {\r\n      width: 100%;\r\n      height: 100%;\r\n      margin: 0;\r\n      padding: 0;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n  &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n  &lt;script&gt;\r\n    \/\/ The stacked area chart's JS code will be written here.\r\n  &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>Step 3: Add the data to visualize<\/h3>\n<h4>Load the data<\/h4>\n<p>The COVID-19 pandemic is the top-news subject worldwide. In this tutorial, I decided to focus on Italy, the first area outside of China that has been tremendously affected by this crisis. I will visualize data with the number of active cases, recoveries, and deaths to see how the situation has been evolving from the beginning of the\u00a0outbreak in Italy until the very present time.<\/p>\n<p>I took data\u00a0from the Johns Hopkins CSSE <a href=\"https:\/\/github.com\/CSSEGISandData\/COVID-19\/tree\/master\/csse_covid_19_data\" target=\"_blank\" rel=\"nofollow\">dataset<\/a>, which is considered a trustworthy source of official COVID-19 statistics.\u00a0For the sake of simplicity,\u00a0I put\u00a0the\u00a0Italian data in\u00a0one CSV file which you can find <a href=\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/covid-19-italy\/data.csv\" target=\"_blank\" rel=\"nofollow\">here<\/a>. Active cases were calculated by subtracting deaths and recoveries from the confirmed cases.<\/p>\n<p><a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Data_Adapter\/Loading_CSV_File\" target=\"_blank\" rel=\"nofollow\">Loading the CSV file<\/a> in AnyChart can be done with the help of the <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Data_Adapter\/Overview\" target=\"_blank\" rel=\"nofollow\">Data Adapter<\/a> module, which you should reference in the <code>&lt;head&gt;<\/code> section in addition to the library&#8217;s scripts that are already referenced there:<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n  &lt;title&gt;Stacked Area Chart&lt;\/title&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-cartesian.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;style&gt;\r\n    html,\r\n    body,\r\n    #container {\r\n      width: 100%;\r\n      height: 100%;\r\n      margin: 0;\r\n      padding: 0;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n  &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n  &lt;script&gt;\r\n    \/\/ The stacked area chart's JS code will be written here.\r\n  &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/code><\/pre>\n<p>Now you can use the <a href=\"https:\/\/api.anychart.com\/v8\/anychart.data#loadCsvFile\" target=\"_blank\" rel=\"nofollow\">loadCsvFile<\/a> method provided by the Data Adapter to load the CSV data.<\/p>\n<pre><code class=\"javascript\">anychart.data.loadCsvFile (\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/covid-19-italy\/data.csv\", function (data) {\r\n});<\/code><\/pre>\n<p>Then, <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Data_Sets\" target=\"_blank\" rel=\"nofollow\">set the data<\/a> to be ready for use in your future JavaScript-based stacked area chart:<\/p>\n<pre><code class=\"javascript\">anychart.data.loadCsvFile (\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/covid-19-italy\/data.csv\", function (data) {\r\n  \/\/ set the data and ignore the first row that contains headers\r\n  var dataSet = anychart.data.set(data, {ignoreFirstRow: true});\r\n});<\/code><\/pre>\n<h4>Map the data<\/h4>\n<p>The chart will display data from three fields: active cases, recoveries, and deaths.\u00a0So you will need three different data series, one for each field. But how will you \u201cinform\u201d your chart which data to use for each field?<\/p>\n<p>Here is where\u00a0<a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Data_Sets#mapping\" target=\"_blank\" rel=\"nofollow\">data mapping<\/a> comes into play! Observe how this is implemented in the code through calling the <a href=\"https:\/\/api.anychart.com\/v8\/anychart.data.Set#mapAs\" target=\"_blank\" rel=\"nofollow\">mapAs<\/a> method:<\/p>\n<pre><code class=\"javascript\">\/\/ map data for the deaths series\r\nvar deathsData = dataSet.mapAs({ 'x': 0, 'value': 2 });\r\n\r\n\/\/ map data for the recovered series\r\nvar recoveredData = dataSet.mapAs({ 'x': 0, 'value': 3 });\r\n\r\n\/\/ map data for the active series\r\nvar activeData = dataSet.mapAs({ 'x': 0, 'value': 4 });<\/code><\/pre>\n<h3>Step 4: Write the JS code for your chart<\/h3>\n<p>Now that everything\u00a0seems to be in place, you are ready to start coding the JS stacked area chart visualization.<\/p>\n<p>First,\u00a0add the <code>anychart.onDocumentReady<\/code> function, which will enclose the whole code of the chart and will be executed when the page is ready.<\/p>\n<pre><code class=\"html\">&lt;script&gt;\r\n\r\nanychart.onDocumentReady(function () {\r\n  \/\/ The stacked area chart's code will be written here.\r\n});\r\n\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>Next, add the data from step 3:<\/p>\n<pre><code class=\"html\">&lt;script&gt;\r\n\r\nanychart.onDocumentReady(function () {\r\n  anychart.data.loadCsvFile (\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/covid-19-italy\/data.csv\", function (data) {\r\n    \/\/ set the data and ignore the first row that contains headers\r\n    var dataSet = anychart.data.set(data, {ignoreFirstRow: true});\r\n  });\r\n});\r\n\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>Then, specify the chart type, set the series and force the chart to stack values by the Y scale:<\/p>\n<pre><code class=\"javascript\">\/\/ specify the area chart type\r\nvar chart = anychart.area();\r\n\r\n\/\/ create a series with the mapped active data\r\nvar actSeries = chart.splineArea(activeData);\r\n\r\n\/\/ create a series with the mapped recovered data\r\nvar recSeries = chart.splineArea(recoveredData);\r\n\r\n\/\/ create a series with the mapped deaths data\r\nvar deathsSeries = chart.splineArea(deathsData);\r\n\r\n\/\/ force the chart to stack values by the y scale\r\nchart.yScale().stackMode('value');<\/code><\/pre>\n<p>For clarity, let\u2019s give it a title and name its axes (see\u00a0<a href=\"https:\/\/www.anychart.com\/blog\/2017\/04\/05\/chart-captions-title-graph-tips\/\">tips on writing great chart captions<\/a>\u00a0if you need\u00a0advice):<\/p>\n<pre><code class=\"javascript\">\/\/ set the chart title\r\nchart.title('Covid-19 in Italy');\r\n\r\n\/\/ set the labels of the axes\r\nchart.xAxis().title(\"Date\");\r\nchart.yAxis().title(\"Number of people\");<\/code><\/pre>\n<p>One more thing: I also want to add a vertical line that will move with the mouse, which should make it easier to see\u00a0where is what at a glance.\u00a0In AnyChart,\u00a0simply use the <a href=\"https:\/\/docs.anychart.com\/Axes_and_Grids\/Crosshair\" target=\"_blank\" rel=\"nofollow\">crosshair<\/a> feature. The following code shows how can enable the crosshair,\u00a0with some additional styling:<\/p>\n<pre><code class=\"javascript\">\/\/ turn on the crosshair\r\nvar crosshair = chart.crosshair();\r\ncrosshair.enabled(true)\r\n  .yStroke(null)\r\n  .xStroke('#fff')\r\n  .zIndex(39);\r\ncrosshair.yLabel().enabled(false);<\/code><\/pre>\n<p>Finally, draw the chart by putting it into the container and using the drawing command.<\/p>\n<pre><code class=\"javascript\">\/\/ set the container id for the chart\r\nchart.container('container');\r\n\r\n\/\/ initiate chart drawing\r\nchart.draw();<\/code><\/pre>\n<p>Enjoy the result:<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-y7Y3OAGf\" src=\"https:\/\/playground.anychart.com\/y7Y3OAGf\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-y7Y3OAGf{width:100%;height:500px;}\");\n})();<\/script><\/p>\n<p>The\u00a0output\u00a0provides insight into how the number of active cases, recoveries, and deaths have been changing over time. The total is all confirmed cases. You can move your mouse over the chart and view the exact\u00a0values\u00a0at each point. Notice how\u00a0the crosshair\u00a0helps in understanding each day\u2019s information!<\/p>\n<p>For your convenience, the full code is below.\u00a0Feel free to play with this <a href=\"https:\/\/playground.anychart.com\/y7Y3OAGf\/\" target=\"_blank\" rel=\"nofollow\">basic JS stacked area chart on\u00a0AnyChart Playground<\/a>.<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n  &lt;title&gt;Stacked Area Chart&lt;\/title&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-cartesian.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;style&gt;\r\n    html,\r\n    body,\r\n    #container {\r\n      width: 100%;\r\n      height: 100%;\r\n      margin: 0;\r\n      padding: 0;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n  &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n  &lt;script&gt;\r\n\r\nanychart.onDocumentReady(function () {\r\n  anychart.data.loadCsvFile(\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/covid-19-italy\/data.csv\", function (data) { \r\n    \/\/ set the data and ignore the first row that contains headers\r\n    var dataSet = anychart.data.set(data, {ignoreFirstRow: true});\r\n\r\n    \/\/ map data for the deaths series\r\n    var deathsData = dataSet.mapAs({ 'x': 0, 'value': 2 });\r\n\r\n    \/\/ map data for the recovered series\r\n    var recoveredData = dataSet.mapAs({ 'x': 0, 'value': 3 });\r\n\r\n    \/\/ map data for the active series\r\n    var activeData = dataSet.mapAs({ 'x': 0, 'value': 4 });\r\n\r\n    \/\/ specify the chart type\r\n    var chart = anychart.area();\r\n\r\n    \/\/ create a series with the mapped active data\r\n    var actSeries = chart.splineArea(activeData);\r\n\r\n    \/\/ create a series with the mapped recovered data\r\n    var recSeries = chart.splineArea(recoveredData);\r\n\r\n    \/\/ create a series with the mapped deaths data\r\n    var deathsSeries = chart.splineArea(deathsData);\r\n\r\n    \/\/ force the chart to stack values by the y scale\r\n    chart.yScale().stackMode('value');\r\n\r\n    \/\/ set the chart title\r\n    chart.title('Covid-19 in Italy');\r\n\r\n    \/\/ set the labels of the axes\r\n    chart.xAxis().title(\"Date\");\r\n    chart.yAxis().title(\"Number of people\");\r\n\r\n    \/\/ turn on the crosshair\r\n    var crosshair = chart.crosshair();\r\n    crosshair.enabled(true)\r\n      .yStroke(null)\r\n      .xStroke('#fff')\r\n      .zIndex(39);\r\n    crosshair.yLabel().enabled(false);\r\n\r\n    \/\/ set the container id for the chart\r\n    chart.container('container');\r\n\r\n    \/\/ initiate chart drawing\r\n    chart.draw();\r\n  });\r\n});\r\n\r\n&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Customizing JavaScript Stacked Area Chart<\/h2>\n<p>It is very likely that different people prefer different functionalities and aesthetics for their charts, let alone different tasks you might get as a web developer or data visualization designer. Luckily, JS charts powered by AnyChart can be modified to fit your needs and preferences with another ease. I will show you how to perform a few quick customizations right now:<\/p>\n<ol>\n<li>Add a legend and animation.<\/li>\n<li>Change values to percentages.<\/li>\n<li>Configure the tooltip, markers and labels.<\/li>\n<li>Change colors.<\/li>\n<\/ol>\n<h3>Add a legend and animation<\/h3>\n<p>Every chart that shows more than one value should have a legend in order to be readable.<\/p>\n<p>Add the following code to turn on a legend for your JS-based stacked area chart.<\/p>\n<pre><code class=\"javascript\">chart.legend(true);<\/code><\/pre>\n<p>I would also like to give this chart a\u00a0bit of wow effect by adding animation. You can quickly make this happen by including\u00a0a short line to the chart&#8217;s JavaScript code:<\/p>\n<pre><code class=\"javascript\">chart.animation(true);<\/code><\/pre>\n<p>Check out the result and you can find this <a href=\"https:\/\/playground.anychart.com\/GgOhYA6p\/\" target=\"_blank\" rel=\"nofollow\">JS stacked area chart with a legend and animation on AnyChart Playground<\/a>:<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-GgOhYA6p\" src=\"https:\/\/playground.anychart.com\/GgOhYA6p\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-GgOhYA6p{width:100%;height:500px;}\");\n})();<\/script><\/p>\n<h3>Change values to percentages<\/h3>\n<p>Now, let&#8217;s\u00a0switch the stacking mode from values to percentages. In this way, you can visualize how the composition has been changing regardless of the total.<\/p>\n<p>It is very straightforward. To make a JavaScript (HTML5)\u00a0<a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/percent-stacked-area-chart\/\">percent stacked area chart<\/a>\u00a0visualizing the same data,\u00a0just replace \u201cvalue\u201d with \u201cpercent\u201d:<\/p>\n<pre><code class=\"javascript\">\/\/ change the stacking mode to percent\r\nchart.yScale().stackMode('percent');<\/code><\/pre>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-lPGKLSbK\" src=\"https:\/\/playground.anychart.com\/lPGKLSbK\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-lPGKLSbK{width:100%;height:500px;}\");\n})();<\/script><\/p>\n<p>This <a href=\"https:\/\/playground.anychart.com\/lPGKLSbK\/\" target=\"_blank\" rel=\"nofollow\">JS percent stacked area chart is available on AnyChart Playground<\/a>.<\/p>\n<h3>Configure the tooltip, markers and labels<\/h3>\n<p>Let&#8217;s make the chart\u00a0display the series\u00a0titles in the tooltip and legend. There are many ways to do this. But I also want to modify\u00a0point markers.\u00a0So\u00a0let&#8217;s create a helper function where you can write the code needed to customize all these elements:<\/p>\n<pre><code class=\"javascript\">\/\/ helper function to setup tooltip labels for all series and style markers\r\nvar setupSeriesLabels = function (series, name) {\r\n  series.name(name)\r\n};<\/code><\/pre>\n<p>Use this function right there where I am setting up the series and add the corresponding titles:<\/p>\n<pre><code class=\"javascript\">\/\/ create a series with the mapped active data\r\nvar actSeries = chart.splineArea(activeData);\r\nsetupSeriesLabels(actSeries, 'Active');\r\n\r\n\/\/ create a series with the mapped recovered data\r\nvar recSeries = chart.splineArea(recoveredData);\r\nsetupSeriesLabels(recSeries, 'Recovered');\r\n\r\n\/\/ create a series with the mapped deaths data\r\nvar deathsSeries = chart.splineArea(deathsData);\r\nsetupSeriesLabels(deathsSeries, 'Deaths');<\/code><\/pre>\n<p>Now, use the helper function again to style the markers. What I am going to do is to make them all circles, give them a specific size, and specify their stroke weight and color. Finally, I will also specify their <a href=\"https:\/\/api.anychart.com\/v8\/anychart.graphics.vector.Element#zIndex\" target=\"_blank\" rel=\"nofollow\"><code>zIndex()<\/code><\/a>\u00a0so that they appear in the front level.<\/p>\n<p>Here is the code:<\/p>\n<pre><code class=\"javascript\">\/\/ helper function to setup series and give them appropriate names in order to distinguish and label them properly\r\nvar setupSeries = function (series, name) {\r\n  series.name(name)\r\n  \/\/ setting the markers\r\n  series.hovered().stroke('3 #fff 1');\r\n  series.hovered().markers()\r\n    .enabled(true)\r\n    .type('circle')\r\n    .size(4)\r\n    .stroke('1.5 #fff');\r\n  series.markers().zIndex(100);\r\n};<\/code><\/pre>\n<p>The\u00a0output of the chart after these changes is as follows:<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-lPGKLSbK\" src=\"https:\/\/playground.anychart.com\/p7MqdGgn\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-p7MqdGgn{width:100%;height:500px;}\");\n})();<\/script><\/p>\n<p>You are welcome to open this <a href=\"https:\/\/playground.anychart.com\/p7MqdGgn\/\" target=\"_blank\" rel=\"nofollow\">customized JS percent stacked area chart on AnyChart Playground<\/a>.<\/p>\n<h3>Change colors<\/h3>\n<p>Finally, I\u00a0want to modify the colors of the chart to something that makes more sense for me. I am going to put a red shaded color for deaths, green for recoveries, and blue for active cases. Feel free to come up with your own ideas!<\/p>\n<p>Here&#8217;s the code:<\/p>\n<pre><code class=\"javascript\">\/\/ create a series with the mapped active series\r\nvar actSeries = chart.splineArea(activeData)\r\n.fill(\"#1E8FCD\")\r\n.stroke(\"#4b9bc6\")\r\nsetupSeries(actSeries, 'Active');\r\n\r\n\/\/ create a series with the mapped recovered data\r\nvar recSeries = chart.splineArea(recoveredData)\r\n.fill(\"#B3C67D\")\r\n.stroke(\"#b9c1a0\")\r\nsetupSeries(recSeries, 'Recovered');\r\n\r\n\/\/ create a series with the mapped deaths data\r\nvar deathsSeries = chart.splineArea(deathsData)\r\n.fill(\"#b3315d\")\r\n.stroke(\"#b5617d\")\r\nsetupSeries(deathsSeries, 'Deaths');<\/code><\/pre>\n<p>Check out\u00a0the final interactive JavaScript percent stacked area chart I showed in a GIF at the very beginning:<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-lPGKLSbK\" src=\"https:\/\/playground.anychart.com\/mHFN31Vt\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-lPGKLSbK{width:100%;height:500px;}\");\n})();<\/script><\/p>\n<p>You can find the whole code of this data visualization below and the <a href=\"https:\/\/playground.anychart.com\/mHFN31Vt\/\" target=\"_blank\" rel=\"nofollow\">final JS percent stacked area chart on AnyChart Playground<\/a>:<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n\r\n&lt;head&gt;\r\n  &lt;title&gt;Stacked Area Chart&lt;\/title&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-cartesian.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;style&gt;\r\n    html,\r\n    body,\r\n    #container {\r\n      width: 100%;\r\n      height: 100%;\r\n      margin: 0;\r\n      padding: 0;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n  &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n    &lt;script&gt;\r\n\r\nanychart.onDocumentReady(function () {\r\n  anychart.data.loadCsvFile(\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/covid-19-italy\/data.csv\", function (data) {\r\n    \/\/ set the data and ignore the first row that contains headers\r\n    var dataSet = anychart.data.set(data, {ignoreFirstRow: true});\r\n\r\n    \/\/ map data for the deaths series\r\n    var deathsData = dataSet.mapAs({ 'x': 0, 'value': 2 });\r\n\r\n    \/\/ map data for the recovered series\r\n    var recoveredData = dataSet.mapAs({ 'x': 0, 'value': 3 });\r\n\r\n    \/\/ map data for the active series\r\n    var activeData = dataSet.mapAs({ 'x': 0, 'value': 4 });\r\n\r\n    \/\/ specify the area chart type\r\n    var chart = anychart.area();\r\n\r\n    \/\/ helper function to setup series and give them appropriate names in order to distinguish and label them properly\r\n    var setupSeries = function (series, name) {\r\n      series.name(name)\r\n      \/\/ setting the markers\r\n      series.hovered().stroke('3 #fff 1');\r\n      series.hovered().markers()\r\n        .enabled(true)\r\n        .type('circle')\r\n        .size(4)\r\n        .stroke('1.5 #fff');\r\n      series.markers().zIndex(100);\r\n    };\r\n\r\n    \/\/ create a series with the mapped active data\r\n    var actSeries = chart.splineArea(activeData)\r\n    .fill(\"#1E8FCD\")\r\n    .stroke(\"#4b9bc6\")\r\n    setupSeries(actSeries, 'Active');\r\n\r\n    \/\/ create a series with the mapped recovered data\r\n    var recSeries = chart.splineArea(recoveredData)\r\n    .fill(\"#B3C67D\")\r\n    .stroke(\"#b9c1a0\")\r\n    setupSeries(recSeries, 'Recovered');\r\n\r\n    \/\/ create a series with the mapped deaths data\r\n    var deathsSeries = chart.splineArea(deathsData)\r\n    .fill(\"#b3315d\")\r\n    .stroke(\"#b5617d\")\r\n    setupSeries(deathsSeries, 'Deaths');\r\n    \r\n    \/\/ force the chart to stack values by the y scale\r\n    chart.yScale().stackMode('percent');\r\n\r\n    \/\/ set the chart title\r\n    chart.title('Covid-19 in Italy');\r\n\r\n    \/\/ set the labels of the axes\r\n    chart.xAxis().title(\"Date\");\r\n    chart.yAxis().title(\"Number of people\");\r\n\r\n    \/\/ turn on the crosshair\r\n    var crosshair = chart.crosshair();\r\n    crosshair.enabled(true)\r\n      .yStroke(null)\r\n      .xStroke('#fff')\r\n      .zIndex(39);\r\n    crosshair.yLabel().enabled(false);\r\n\r\n    \/\/ turn on the legend\r\n    chart.legend(true);\r\n\r\n    \/\/ turn on the chart animation\r\n    chart.animation(true);\r\n\r\n    \/\/ set the container id for the chart\r\n    chart.container('container');\r\n\r\n    \/\/ initiate chart drawing\r\n    chart.draw();\r\n  });\r\n});\r\n\r\n&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>Congratulations! You&#8217;ve just build your\u00a0first\u00a0JavaScript stacked area charts!\u00a0The process is not really\u00a0difficult, is it?<\/p>\n<p>Go ahead and keep learning while it&#8217;s hot. See the\u00a0<a href=\"https:\/\/docs.anychart.com\" target=\"_blank\" rel=\"nofollow\">documentation<\/a>. Check some more examples of stacked area charts in the <a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/Area_Charts\/\">area charts gallery<\/a> for inspiration.\u00a0Feel free to share your own creations and post your questions in the comments\u00a0?<\/p>\n<p>Wondering how to visualize data in other charts? See\u00a0more <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JS charting tutorials<\/a> in the AnyChart blog.<\/p>\n<hr \/>\n<p><strong><em>See also: <a href=\"https:\/\/www.anychart.com\/blog\/2017\/10\/28\/create-javascript-area-chart\/\">How to Create JavaScript Area Chart<\/a><\/em><\/strong><\/p>\n<hr \/>\n<p><!-- SyntaxHighlighter --><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/default.min.css\"><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/atom-one-light.min.css\"><script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/highlight.min.js\"><\/script><script>hljs.initHighlightingOnLoad();<\/script><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Stacked area charts,\u00a0a variation of classic area charts, are quite a popular form of data visualization.\u00a0They\u00a0work\u00a0great to\u00a0graphically represent how\u00a0multiple\u00a0variables\u00a0and their totals are changing over time. In this tutorial, I will show you how to easily create\u00a0an interactive JavaScript stacked area chart\u00a0which will\u00a0look compelling\u00a0in any HTML5 project, web site or app. To demonstrate this way, which [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,23,13,279,4],"tags":[53,72,73,35,284,127,258,1766,1823,1773,1771,1772,1819,1800,1801,1803,1804,1925,1977,1769,1975,1936,1954,1824,1935,471,266,509,54,256,844,259,1762,32,55,144,36,907,141,249,81,57,1238,58,56,101,1768,189,105,188,1244,459,30,172,1767],"class_list":["post-10634","post","type-post","status-publish","format-standard","hentry","category-anychart-charting-component","category-html5","category-javascript","category-javascript-chart-tutorials","category-tips-and-tricks","tag-anychart","tag-area-chart","tag-area-charts","tag-business-intelligence","tag-chart-examples","tag-chart-types","tag-charts","tag-coronavirus","tag-coronavirus-cases","tag-coronavirus-charts","tag-coronavirus-data","tag-coronavirus-data-visualization","tag-coronavirus-outbreak","tag-coronavirus-pandemic","tag-coronavirus-pandemic-charts","tag-coronavirus-pandemic-data","tag-coronavirus-pandemic-data-visualization","tag-covid","tag-covid-charting-library","tag-covid-19","tag-covid-19-analytics","tag-covid-19-cases","tag-covid-19-charts","tag-covid-19-deaths","tag-covid-19-statistics","tag-data-analysis","tag-data-analytics","tag-data-graphics","tag-data-visualization","tag-data-visualization-examples","tag-data-visualization-tutorial","tag-graphs","tag-guest-post","tag-html5","tag-html5-charts","tag-infographics","tag-javascript","tag-javascript-chart-tutorial","tag-javascript-charting","tag-javascript-charting-api","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-graph","tag-js-chart","tag-js-charts","tag-js-graphics","tag-novel-coronavirus","tag-percent-stacked-area-chart","tag-spline-area-charts","tag-stacked-area-chart","tag-stacked-area-charts","tag-statistics","tag-tips-and-tricks","tag-tutorial","tag-wuhan-coronavirus","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Stacked Area Chart: How to Create One with JavaScript (HTML5)<\/title>\n<meta name=\"description\" content=\"A new tutorial explains how to create a JavaScript stacked area chart for a website or app, visualizing COVID-19 data for Italy over time for illustration.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Stacked Area Chart with JavaScript\" \/>\n<meta property=\"og:description\" content=\"This tutorial explains how to create a JS stacked area chart for a website or app, visualizing COVID-19 data for Italy over time for illustration.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"AnyChart News\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/AnyCharts\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-10T00:00:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-13T10:59:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/Data-Visualization-Weekly-August-5-12-2022-Social.png\" \/>\n<meta name=\"author\" content=\"Anastasia Zoumpliou\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"How to Create Stacked Area Chart with JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"This tutorial explains how to create a JS stacked area chart for a website or app, visualizing COVID-19 data for Italy over time for illustration.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/Data-Visualization-Weekly-August-5-12-2022-Social.png\" \/>\n<meta name=\"twitter:creator\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:site\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anastasia Zoumpliou\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/\"},\"author\":{\"name\":\"Anastasia Zoumpliou\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff\"},\"headline\":\"How to Create Stacked Area Chart with JavaScript\",\"datePublished\":\"2020-06-10T00:00:34+00:00\",\"dateModified\":\"2022-08-13T10:59:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/\"},\"wordCount\":1565,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial.png\",\"keywords\":[\"AnyChart\",\"area chart\",\"area charts\",\"Business Intelligence\",\"chart examples\",\"chart types\",\"charts\",\"coronavirus\",\"coronavirus cases\",\"coronavirus charts\",\"coronavirus data\",\"coronavirus data visualization\",\"coronavirus outbreak\",\"coronavirus pandemic\",\"coronavirus pandemic charts\",\"coronavirus pandemic data\",\"coronavirus pandemic data visualization\",\"covid\",\"COVID charting library\",\"COVID-19\",\"COVID-19 analytics\",\"COVID-19 cases\",\"COVID-19 charts\",\"COVID-19 deaths\",\"COVID-19 statistics\",\"data analysis\",\"data analytics\",\"data graphics\",\"Data Visualization\",\"data visualization examples\",\"data visualization tutorial\",\"graphs\",\"guest post\",\"HTML5\",\"html5 charts\",\"infographics\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"javascript charting api\",\"JavaScript charting library\",\"javascript charts\",\"javascript graph\",\"js chart\",\"js charts\",\"JS graphics\",\"novel coronavirus\",\"percent stacked area chart\",\"spline area charts\",\"stacked area chart\",\"stacked area charts\",\"statistics\",\"Tips and tricks\",\"tutorial\",\"Wuhan coronavirus\"],\"articleSection\":[\"AnyChart Charting Component\",\"HTML5\",\"JavaScript\",\"JavaScript Chart Tutorials\",\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/\",\"name\":\"Stacked Area Chart: How to Create One with JavaScript (HTML5)\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial.png\",\"datePublished\":\"2020-06-10T00:00:34+00:00\",\"dateModified\":\"2022-08-13T10:59:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff\"},\"description\":\"A new tutorial explains how to create a JavaScript stacked area chart for a website or app, visualizing COVID-19 data for Italy over time for illustration.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial.png\",\"width\":1700,\"height\":956},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Stacked Area Chart with JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\",\"url\":\"https:\/\/www.anychart.com\/blog\/\",\"name\":\"AnyChart News\",\"description\":\"AnyChart JS Charts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.anychart.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff\",\"name\":\"Anastasia Zoumpliou\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/774bd2dbe4c628607dd7ac40f009135e92ba9ab1027bccf9f63351bca2dd919e?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/774bd2dbe4c628607dd7ac40f009135e92ba9ab1027bccf9f63351bca2dd919e?s=96&r=g\",\"caption\":\"Anastasia Zoumpliou\"},\"url\":\"https:\/\/www.anychart.com\/blog\/author\/anastasia-zoumpliou\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Stacked Area Chart: How to Create One with JavaScript (HTML5)","description":"A new tutorial explains how to create a JavaScript stacked area chart for a website or app, visualizing COVID-19 data for Italy over time for illustration.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Stacked Area Chart with JavaScript","og_description":"This tutorial explains how to create a JS stacked area chart for a website or app, visualizing COVID-19 data for Italy over time for illustration.","og_url":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2020-06-10T00:00:34+00:00","article_modified_time":"2022-08-13T10:59:48+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/Data-Visualization-Weekly-August-5-12-2022-Social.png","type":"","width":"","height":""}],"author":"Anastasia Zoumpliou","twitter_card":"summary_large_image","twitter_title":"How to Create Stacked Area Chart with JavaScript","twitter_description":"This tutorial explains how to create a JS stacked area chart for a website or app, visualizing COVID-19 data for Italy over time for illustration.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/Data-Visualization-Weekly-August-5-12-2022-Social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Anastasia Zoumpliou","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/"},"author":{"name":"Anastasia Zoumpliou","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff"},"headline":"How to Create Stacked Area Chart with JavaScript","datePublished":"2020-06-10T00:00:34+00:00","dateModified":"2022-08-13T10:59:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/"},"wordCount":1565,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial.png","keywords":["AnyChart","area chart","area charts","Business Intelligence","chart examples","chart types","charts","coronavirus","coronavirus cases","coronavirus charts","coronavirus data","coronavirus data visualization","coronavirus outbreak","coronavirus pandemic","coronavirus pandemic charts","coronavirus pandemic data","coronavirus pandemic data visualization","covid","COVID charting library","COVID-19","COVID-19 analytics","COVID-19 cases","COVID-19 charts","COVID-19 deaths","COVID-19 statistics","data analysis","data analytics","data graphics","Data Visualization","data visualization examples","data visualization tutorial","graphs","guest post","HTML5","html5 charts","infographics","JavaScript","javascript chart tutorial","javascript charting","javascript charting api","JavaScript charting library","javascript charts","javascript graph","js chart","js charts","JS graphics","novel coronavirus","percent stacked area chart","spline area charts","stacked area chart","stacked area charts","statistics","Tips and tricks","tutorial","Wuhan coronavirus"],"articleSection":["AnyChart Charting Component","HTML5","JavaScript","JavaScript Chart Tutorials","Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/","url":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/","name":"Stacked Area Chart: How to Create One with JavaScript (HTML5)","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial.png","datePublished":"2020-06-10T00:00:34+00:00","dateModified":"2022-08-13T10:59:48+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff"},"description":"A new tutorial explains how to create a JavaScript stacked area chart for a website or app, visualizing COVID-19 data for Italy over time for illustration.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/06\/stacked-area-chart-javascript-html5-tutorial.png","width":1700,"height":956},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2020\/06\/10\/stacked-area-chart-javascript-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Stacked Area Chart with JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.anychart.com\/blog\/#website","url":"https:\/\/www.anychart.com\/blog\/","name":"AnyChart News","description":"AnyChart JS Charts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.anychart.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff","name":"Anastasia Zoumpliou","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/774bd2dbe4c628607dd7ac40f009135e92ba9ab1027bccf9f63351bca2dd919e?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/774bd2dbe4c628607dd7ac40f009135e92ba9ab1027bccf9f63351bca2dd919e?s=96&r=g","caption":"Anastasia Zoumpliou"},"url":"https:\/\/www.anychart.com\/blog\/author\/anastasia-zoumpliou\/"}]}},"_links":{"self":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/10634","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/comments?post=10634"}],"version-history":[{"count":40,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/10634\/revisions"}],"predecessor-version":[{"id":15496,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/10634\/revisions\/15496"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=10634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=10634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=10634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}