{"id":14786,"date":"2022-04-12T07:41:47","date_gmt":"2022-04-12T07:41:47","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=14786"},"modified":"2022-08-13T11:10:59","modified_gmt":"2022-08-13T11:10:59","slug":"stacked-chart","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/","title":{"rendered":"How to Create Stacked Chart with JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart.png\" alt=\"A stacked chart on a laptop screen as a title illustration for this stack chart guide\" width=\"100%\" class=\"alignnone size-full wp-image-14793\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart.png 1800w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-300x167.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-768x427.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-1024x569.png 1024w\" sizes=\"(max-width: 1800px) 100vw, 1800px\" \/><\/a><a href=\"https:\/\/www.anychart.com\/blog\/2018\/11\/20\/data-visualization-definition-history-examples\/\">Data visualization<\/a> is a skill vital for analysts and developers in the current times. Stacked charts are one of the most widely used chart types, and now I want to tell you what they are and how to build such graphics with ease using JavaScript. In the main tutorial part, I will be creating different versions of a stacked chart, providing comprehensive step-by-step instructions to let you learn fast. My visualizations will offer a look at the medal counts for the top 10 countries on the final Beijing 2022 Winter Olympics leaderboard so you also have fun as you follow along.<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>What Is Stacked Chart?<\/h2>\n<p>A stacked chart is a variation of a <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/bar-chart\/\">bar chart<\/a>, a <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/column-chart\/\">column chart<\/a>, or an <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/area-chart\/\">area chart<\/a> that provides a look at the composition of total values to enrich comparisons (or over-time tracking) in visual data analysis.<\/p>\n<p>Stacked charts are effective when you need to graphically aggregate parts of a (changing) whole.<\/p>\n<h2>Stacked Chart Types<\/h2>\n<p>There are two major types of stacked charts: value-based and percentage-based.<\/p>\n<p>A value stacked chart \u2014 or simply a stacked chart \u2014 represents totals by category while offering a bird\u2019s-eye view of the composition by series, all in absolute values. Such graphics are helpful for comparing totals across several categories and, at the same time, understanding the role of each series in the differences revealed during a quick visual analysis.<\/p>\n<p>A percent stacked chart \u2014 sometimes also called a 100% stacked chart \u2014 visualizes percentages instead of absolute values. It represents totals by category as 100% and individual data points within the series as proportions in relation to the whole. Such plots are ideal for observing how the contribution of a certain series changes from category to category when absolute totals themselves are not to take into account.<\/p>\n<p>Depending on the initial, base form of a series visualization, such a graphic can be called a <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/stacked-bar-chart\/\">stacked bar chart<\/a>, a <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/stacked-column-chart\/\">stacked column chart<\/a>, or a <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/stacked-area-chart\/\">stacked area chart<\/a> \u2014 or, respectively, a <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/percent-stacked-bar-chart\/\">percent stacked bar chart<\/a>, a <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/percent-stacked-column-chart\/\">percent stacked column chart<\/a>, or a <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/percent-stacked-area-chart\/\">percent stacked area chart<\/a>.<\/p>\n<p>Don\u2019t miss out on reading an awesome <a href=\"https:\/\/www.smashingmagazine.com\/2017\/03\/understanding-stacked-bar-charts\/\" target=\"_blank\" rel=\"nofollow\">article about stacked bar charts<\/a> on Smashing Magazine, for example, to get a deep dive into how this stacked chart type works and should be used the right way.<\/p>\n<h2>Stacked Chart Example That Will Be Built<\/h2>\n<p>Now, it\u2019s time for the tutorial itself! I will explain how to create a cool interactive stacked chart without hassle using JavaScript.<\/p>\n<p>The first stacked chart to be built in the tutorial is an interactive stacked column chart. After that, I\u2019ll show you how to customize it in a few lines of code. Finally, you will learn how to convert a stacked column chart into a percent stacked column chart and into a stacked bar chart, which will also be extremely straightforward.<\/p>\n<p>Still under the impression of last month\u2019s <a href=\"https:\/\/www.anychart.com\/blog\/2022\/02\/25\/beijing-olympics-medal-trackers\/\">Beijing 2022 Winter Olympics<\/a>, I decided to look at the 10 countries with the most Olympic medals won, visualizing how many total medals \u2014 and gold, silver, and bronze \u2014 their athletes took home.<\/p>\n<p>Take a look at the final JavaScript-based stacked chart that I will get by the end of this tutorial!<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-preview.png\" alt=\"The JavaScript-based stacked chart built in the tutorial\" width=\"100%\" class=\"alignnone size-full wp-image-14795\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-preview.png 1220w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-preview-300x160.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-preview-768x409.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-preview-1024x546.png 1024w\" sizes=\"(max-width: 1220px) 100vw, 1220px\" \/><\/p>\n<h2>Building JavaScript Stacked Chart<\/h2>\n<p>An impressive JS stacked chart can be built in just 4 simple steps. <\/p>\n<ul>\n<li>Create a basic HTML page.<\/li>\n<li>Include the necessary JS files.<\/li>\n<li>Add the data.<\/li>\n<li>Write the required JavaScript code.<\/li>\n<\/ul>\n<h3>1. Create a basic HTML page<\/h3>\n<p>First things first. I create a basic HTML page. To define a place where I want to put the stacked chart that I will make, I include a block element (<code>&lt;div&gt;<\/code>) and give it an ID (\u201ccontainer\u201d) to easily refer to this <code>&lt;div&gt;<\/code> later in the code.<\/p>\n<pre><code>&lt;html&gt;\r\n&nbsp;&nbsp;&lt;head&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;JavaScript Stacked Chart&lt;\/title&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;style type=\"text\/css\"&gt;      \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html, body, #container { \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width: 100%; height: 100%; margin: 0; padding: 0; \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} \r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/style&gt;\r\n&nbsp;&nbsp;&lt;\/head&gt;\r\n&nbsp;&nbsp;&lt;body&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n&nbsp;&nbsp;&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<p>Then, I set the width and height of the container element to 100% to render the stacked chart over the full web page. It goes without saying that you can adjust these parameters to your liking.<\/p>\n<h3>2. Include the necessary JavaScript files<\/h3>\n<p>Next, I need to reference all scripts that will be used to create my stacked chart. I will do it in the <code>&lt;head&gt;<\/code> section of the HTML page I\u2019ve just created.<\/p>\n<p>In this tutorial, I am using <a href=\"https:\/\/www.anychart.com\">AnyChart<\/a>. It is a lightweight JS (HTML5) charting library with many options for <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Supported_Charts_Types\" target=\"_blank\" rel=\"nofollow\">chart types<\/a>, including stacked charts, and for what you want to get from their look and feel. And it can be a good fit for beginners in data visualization development for the web because of thorough <a href=\"https:\/\/docs.anychart.com\" target=\"_blank\" rel=\"nofollow\">documentation<\/a> and many ready-to-use <a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/\">chart examples<\/a>.<\/p>\n<p>AnyChart has a <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules\" target=\"_blank\" rel=\"nofollow\">modular<\/a> system, which allows you to minimize the amount of JavaScript code executed on your web page by connecting only those chart types and features that you will actually use, not the entire library. To build a stacked chart of literally any Cartesian type, the <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#base\" target=\"_blank\" rel=\"nofollow\">base module<\/a> is enough. Let me obtain it from the <a href=\"https:\/\/cdn.anychart.com\" target=\"_blank\" rel=\"nofollow\">CDN<\/a> (alternately, of course, you can download it if you want).<\/p>\n<pre><code>&lt;html&gt;\r\n&nbsp;&nbsp;&lt;head&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;JavaScript Stacked Chart&lt;\/title&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-base.min.js\"&gt;&lt;\/script&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;style type=\"text\/css\"&gt;      \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html, body, #container { \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width: 100%; height: 100%; margin: 0; padding: 0; \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} \r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/style&gt;\r\n&nbsp;&nbsp;&lt;\/head&gt;\r\n&nbsp;&nbsp;&lt;body&gt;  \r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;script&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ All the code for the JS stacked chart will come here.\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/script&gt;\r\n&nbsp;&nbsp;&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>3. Add the data<\/h3>\n<p>Let\u2019s take data on medal counts by country from the <a href=\"https:\/\/olympics.com\/beijing-2022\/olympic-games\/en\/results\/all-sports\/medal-standings.htm\" target=\"_blank\" rel=\"nofollow\">Olympic medal table<\/a> available on the official Beijing 2022 Winter Olympics website. Since this data is uncomplicated and limited, I will directly add it to the code in the form of an <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Data_Sets#array_of_arrays\" target=\"_blank\" rel=\"nofollow\">array of arrays<\/a>. (Multiple other <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Supported_Data_Formats\" target=\"_blank\" rel=\"nofollow\">ways to load data<\/a> are also at your service, of course.) The numerical values coming after the country name will stand for the number of medals won \u2014 gold, silver, and bronze, respectively.<\/p>\n<pre><code class=\"javascript\">let data = anychart.data.set([\r\n  ['Norway',16,8,13],\r\n  ['ROC',6,12,14],\r\n  ['Germany',12,10,5],\r\n  ['Canada',4,8,14],\r\n  ['USA',8,10,7],\r\n  ['Sweden',8,5,5],\r\n  ['Austria',7,7,4],\r\n  ['Japan',3,6,9],\r\n  ['Netherlands',8,5,4],\r\n  ['Italy',2,7,8]\r\n]);<\/code><\/pre>\n<p>The stage for a JS-based stacked chart is all set as now we\u2019ve got a web page, scripts, and data. Now, it\u2019s time for the main event, so get ready to add some JavaScript code for the visualization!<\/p>\n<h3>4. Write the required JavaScript code<\/h3>\n<p>Before doing anything else, I add an enclosing function ensuring that the JS code inside of it runs only once the page is ready. The first thing I include is the data from step 3.<\/p>\n<pre><code class=\"javascript\">anychart.onDocumentReady(function () {\r\n\r\n  \/\/ create a dataset\r\n  let data = anychart.data.set([\r\n    ['Norway',16,8,13],\r\n    ['ROC',6,12,14],\r\n    ['Germany',12,10,5],\r\n    ['Canada',4,8,14],\r\n    ['USA',8,10,7],\r\n    ['Sweden',8,5,5],\r\n    ['Austria',7,7,4],\r\n    ['Japan',3,6,9],\r\n    ['Netherlands',8,5,4],\r\n    ['Italy',2,7,8]\r\n  ]);\r\n\r\n  \/\/ everything else goes here\r\n\r\n});<\/code><\/pre>\n<p>A JavaScript-based stacked column chart is quite straightforward to create and believe me, it\u2019s just a few lines of easy-to-understand code! <\/p>\n<p>Since I am showcasing three different types of medals, I need three series, each representing gold, silver, and bronze medals. Firstly, I map the data for each series.<\/p>\n<pre><code class=\"javascript\">\/\/ map the data for the first series\r\nlet firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });\r\n\r\n\/\/ map the data for the second series\r\nlet secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });\r\n\r\n\/\/ map the data for the second series\r\nlet thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });<\/code><\/pre>\n<p>Then, I create a column chart instance and specify that I want to stack the values over the Y scale.<\/p>\n<pre><code class=\"javascript\">\/\/ create a column chart instance\r\nlet chart = anychart.column();\r\n\r\n\/\/ stack values on y scale.\r\nchart.yScale().stackMode('value');<\/code><\/pre>\n<p>Next, I create all three series with the mapped data.<\/p>\n<pre><code class=\"javascript\">\/\/ store series\r\nlet series;\r\n\r\n\/\/ create the first series with the mapped data\r\nseries = chart.column(firstSeriesData);\r\n\r\n\/\/ create the second series with the mapped data\r\nseries = chart.column(secondSeriesData);\r\n\r\n\/\/ create the third series with the mapped data\r\nseries = chart.column(thirdSeriesData);<\/code><\/pre>\n<p>Lastly, I give a title to the chart, set the container ID (remember it from the first step \u2014 that\u2019s where it is needed), and draw the resulting stacked chart.<\/p>\n<pre><code class=\"javascript\">\/\/ set the chart title\r\nchart.title(\"Winter Olympics 2022 Medal Tally\");\r\n\r\n\/\/ 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>It\u2019s over \u2014 a fully functional JS stacked chart with column series is ready!<\/p>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-hLzNTIfp\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/hLzNTIfp\/iframe\"><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-hLzNTIfp{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>It has been an easy-to-follow process for creating a beautiful JavaScript stacked chart in a jiffy, isn\u2019t it? And now, you can see at a glance how European nations are dominating the Olympic medal race and can delve into other details to analyze.<\/p>\n<p>This basic version of the stacked chart with the full JS\/CSS\/HTML code is available on <a href=\"https:\/\/playground.anychart.com\/hLzNTIfp\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.<\/p>\n<p>Actually, the resulting visualization already looks good to me. But let me show you how you can customize this stacked chart in case you ever need it.<\/p>\n<h2>Customizing Stacked Chart<\/h2>\n<p>Once you\u2019ve created a basic JavaScript stacked chart, customizing it is even less tricky. Here are some possible tweaks that you might like to make.<\/p>\n<h3>1. Series name<\/h3>\n<p>The stacked chart contains three series indicating individual medal types. But why does someone has to guess which one is where?<\/p>\n<p>To avoid any confusion, I want to name each series according to the type of medal it represents. Then these names will be specified in the tooltip showing up when the mouse cursor hovers over the corresponding series \u2014 instead of meaningless \u201cSeries 0,\u201d \u201cSeries 1,\u201d and \u201cSeries 2.\u201d<\/p>\n<p>So, I create a function that takes the series and the name as the parameters and sets the name of the series based on the obtained value. Then I simply pass the series and the name of that series for each series.<\/p>\n<pre><code class=\"javascript\">\/\/ a function to set the series names\r\nlet setupSeries = function (series, name) {\r\n  series.name(name);\r\n};\r\n\r\n\/\/ create the first series with the mapped data\r\nseries = chart.column(firstSeriesData);\r\nsetupSeries(series, \"Gold\");\r\n                  \r\n\/\/ create the second series with the mapped data\r\nseries = chart.column(secondSeriesData);\r\nsetupSeries(series, \"Silver\");\r\n\r\n\/\/ create the third series with the mapped data\r\nseries = chart.column(thirdSeriesData);\r\nsetupSeries(series, \"Bronze\");<\/code><\/pre>\n<h3>2. Color palette<\/h3>\n<p>A really effective way of making a chart look more impressive and personalized as well as highlighting something in data is using relevant colors. In my JS stacked chart, I can simply pick the colors for each series according to the medal type.<\/p>\n<p>To do this, I add the color parameter to the function created in the previous step and pass the corresponding color for each series \u2014 to make it look like gold, silver, or bronze, respectively. When hovered, I let it turn to a darker shade of the same color.<\/p>\n<pre><code class=\"javascript\">\/\/ a function to configure label, padding, and color settings for all series\r\nlet setupSeries = function (series, name, color, hoveredColor) {\r\n  series.name(name).stroke(\"2 #fff 1\").fill(color);\r\n  series.hovered().stroke(\"1 #fff 1\").fill(hoveredColor);\r\n};\r\n\r\n\u2026\r\n\r\n\/\/ create the first series with the mapped data\r\nseries = chart.column(firstSeriesData);\r\nsetupSeries(series, \"Gold\", \"#f9cd0e\", \"#dfb80c\");\r\n\r\n\/\/ create the second series with the mapped data\r\nseries = chart.column(secondSeriesData);\r\nsetupSeries(series, \"Silver\", \"#afb7c0\", \"#9aa0a6\");\r\n\r\n\/\/ create the third series with the mapped data\r\nseries = chart.column(thirdSeriesData);\r\nsetupSeries(series, \"Bronze\", \"#cc8469\", \"#ae7058\");<\/code><\/pre>\n<p>Now, it is so much more intuitive. You can quickly understand which country won how many medals of each type. For example, I can immediately see that Norway\u2019s athletes took home not only the most total medals but also the most gold ones.<\/p>\n<h3>3. Legend<\/h3>\n<p>For my current stacked chart, the colors are pretty obvious. Nonetheless, I will show you how to add a legend that indicates exactly what each color represents.<\/p>\n<p>Actually, it is very easy as you can simply enable the legend and it will appear automatically. I also want to specify the font size of the legend and add a bit of top padding. But it can still be just one straightforward line of code.<\/p>\n<pre><code class=\"javascript\">chart.legend().enabled(true).fontSize(16).padding([10, 0, 0, 0]);<\/code><\/pre>\n<h3>3. Title enhancement<\/h3>\n<p>To make it all more pronounced, I add some formatting to the stack chart title. I increase the font size, give it a darker color, and set a larger padding.<\/p>\n<pre><code class=\"javascript\">chart.title().fontSize(20).fontColor(\"#2b2b2b\").padding([5, 0, 0, 0]);<\/code><\/pre>\n<p>Check out how lovely this enhanced version of the JS-based stacked column chart looks! <a href=\"https:\/\/playground.anychart.com\/GanVhCMH\/\" target=\"_blank\" rel=\"nofollow\">Here<\/a> is the full code with all the recent modifications. <\/p>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-GanVhCMH\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/GanVhCMH\/iframe\"><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-GanVhCMH{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h3>4. Tooltip improvement<\/h3>\n<p>I feel that a tooltip is a great way to share more information with the reader. In this example of a JavaScript stacked chart, I will add the total number of medals won by each country to the tooltip along with the types of the medals.<\/p>\n<p>Before that, I want to make sure that a single tooltip \u2014 one for all series \u2014 shows up when the mouse cursor is moved to any part of a column. This can be achieved with the \u201cunion\u201d tooltip display mode.<\/p>\n<pre><code class=\"javascript\">chart.tooltip().displayMode(\"union\");<\/code><\/pre>\n<p>Now, I format the stacked chart\u2019s title so it displays the total number of medals along with the corresponding country\u2019s name. To do this, I create a function and add medal count values for each type.<\/p>\n<pre><code class=\"javascript\">chart.tooltip().titleFormat(function(e){\r\n  return this.x + ' - ' + this.points[0].getStat('categoryYSum');\r\n});<\/code><\/pre>\n<p>Now the tooltip is so much more intuitive and informative!<\/p>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-sCrJ3Hrc\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/sCrJ3Hrc\/iframe\"><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-sCrJ3Hrc{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>You can find the full code for this JavaScript stacked chart <a href=\"https:\/\/playground.anychart.com\/sCrJ3Hrc\/\" target=\"_blank\" rel=\"nofollow\">here<\/a>.<\/p>\n<p>So, it is a cool interactive stacked column chart built with JS. But what about other types of stacked charts? As a bonus, I will also show you how to easily make two other variations: a percent stacked column chart and a stacked bar chart.<\/p>\n<h3>5. Percent stacked column chart<\/h3>\n<p>When you need to focus on composition rather than totals, a percent stacked chart comes to shine. With this data visualization technique, all eyes are on percentages.<\/p>\n<p>To turn a value-based stacked column chart into a percentage-based stacked chart, all you need is to replace \u201cvalue\u201d with \u201cpercent\u201d when specifying the mode of stacking. So easy!<\/p>\n<pre><code class=\"javascript\">chart.yScale().stackMode(\"percent\");<\/code><\/pre>\n<p>Check out the code for this JavaScript percent stacked column chart <a href=\"https:\/\/playground.anychart.com\/H91yg0GQ\/\" target=\"_blank\" rel=\"nofollow\">here<\/a>.<\/p>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-H91yg0GQ\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/H91yg0GQ\/iframe\"><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-H91yg0GQ{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h3>6. Stacked bar chart<\/h3>\n<p>If you like horizontal bars more than vertical \u2014 or, for example, if series names are just too long and do not fit well \u2014 you may like to create a stacked bar chart instead of a stacked column chart. Well, it is far from rocket science as well and can be done in exactly the same manner.<\/p>\n<p>Right now, I just change <code>column<\/code> to <code>bar<\/code> everywhere.<\/p>\n<pre><code class=\"javascript\">let chart = anychart.bar();\r\n\u2026\r\nseries = chart.bar(firstSeriesData);\r\n\u2026\r\nseries = chart.bar(secondSeriesData);\r\n\u2026\r\nseries = chart.bar(thirdSeriesData);<\/code><\/pre>\n<p>The resulting interactive JavaScript stacked bar chart is the final visualization of my JS stacked chart tutorial! You are more than welcome to play with the code of this version on <a href=\"https:\/\/playground.anychart.com\/bf0yXgIb\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a> and add your own one to your website or app.<\/p>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-bf0yXgIb\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/bf0yXgIb\/iframe\"><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-bf0yXgIb{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h2>Conclusion<\/h2>\n<p>As you see, it is simple to quickly create and customize a JS stacked chart. Indeed, the process does not require too much technical knowledge or experience. Please get in touch if you have any questions.<\/p>\n<p>Now, do you want to see how other <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Supported_Charts_Types\" target=\"_blank\" rel=\"nofollow\">chart types<\/a> can be built with ease? Check out a series of <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a> many of which were created by me, too!<\/p>\n<p>The Olympic Games are always an inspiration. As a matter of fact, it is easier to create great interactive data visualizations than to win such top-class medals. So get going and score a win with some beautiful and insightful charts and dashboards!<\/p>\n<hr \/>\n<p><em>We are thankful to Shachee Swadia, a freelance data visualization developer, for writing this amazing article about stacked charts.<\/p>\n<p>Got an idea for a guest post? We will be happy to <a href=\"https:\/\/www.anychart.com\/support\/\">hear<\/a> from you about it!<\/p>\n<p>Don&#8217;t miss out on seeing our other <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a><\/em><\/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>Data visualization is a skill vital for analysts and developers in the current times. Stacked charts are one of the most widely used chart types, and now I want to tell you what they are and how to build such graphics with ease using JavaScript. In the main tutorial part, I will be creating different [&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":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,23,13,279,4],"tags":[619,618,53,3173,70,71,3337,3335,3338,3339,3336,260,561,1758,3149,284,127,258,290,85,160,471,266,620,1759,294,257,2220,2838,54,1389,1760,2757,256,1111,350,744,1379,844,165,313,1370,774,1498,805,1762,2013,2014,32,55,77,1335,144,167,143,146,433,79,152,2949,80,151,247,36,907,141,249,3111,81,57,76,1238,142,99,134,58,65,78,101,2726,2723,2718,2660,2720,189,185,3360,3361,835,2898,188,1244,87,581,187,580,834,459,30,172,807,808,954,293,745,899,108,2015,2816,1763,804,3334],"class_list":["post-14786","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-analysis","tag-analytics","tag-anychart","tag-app-development","tag-bar-chart","tag-bar-charts","tag-beijing","tag-beijing-2022","tag-beijing-2022-country-standings","tag-beijing-2022-medal-counts","tag-beijing-2022-olympics","tag-best-data-visualization-examples","tag-best-data-visualizations","tag-chart-design","tag-chart-development","tag-chart-examples","tag-chart-types","tag-charts","tag-column-chart","tag-column-charts","tag-dashboard-design","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-design","tag-data-science","tag-data-stories","tag-data-visual","tag-data-visualisation","tag-data-visualization","tag-data-visualization-best-pracices","tag-data-visualization-design","tag-data-visualization-development","tag-data-visualization-examples","tag-data-visualization-practice","tag-data-visualization-projects","tag-data-visualization-techniques","tag-data-visualization-tool","tag-data-visualization-tutorial","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-dataviz-examples","tag-example","tag-front-end-development","tag-guest-post","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-html5-dashboards","tag-infographic","tag-infographics","tag-interactive-charts","tag-interactive-dashboard","tag-interactive-data-visualization","tag-interactive-graphics","tag-interactive-html5-dashboard","tag-interactive-infographic","tag-interactive-infographics","tag-interactive-javascript-dashboard","tag-interactive-visualizations","tag-interactivity","tag-javascript","tag-javascript-chart-tutorial","tag-javascript-charting","tag-javascript-charting-api","tag-javascript-charting-features","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-dashboards","tag-javascript-graph","tag-javascript-graphics","tag-javascript-library","tag-javascript-technologies","tag-js-chart","tag-js-charting","tag-js-dashboards","tag-js-graphics","tag-medal-count-charts","tag-olympic-games","tag-olympic-medal-count","tag-olympics","tag-olympics-country-standings","tag-percent-stacked-area-chart","tag-percent-stacked-bar-chart","tag-percent-stacked-chart","tag-smashing-magazine","tag-sports","tag-sports-data-visualization","tag-stacked-area-chart","tag-stacked-area-charts","tag-stacked-bar-chart","tag-stacked-bar-charts","tag-stacked-charts","tag-stacked-column-charts","tag-statistical-analysis","tag-statistics","tag-tips-and-tricks","tag-tutorial","tag-visual-analysis","tag-visual-analytics","tag-visual-data-analytics","tag-visualization","tag-visualization-techniques","tag-visualizations","tag-web-analytics","tag-web-charts","tag-web-design","tag-web-developers","tag-web-development","tag-winter-olympics","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 Chart: Definition, Types &amp; How to Create It with JavaScript<\/title>\n<meta name=\"description\" content=\"Looking for information on a stacked chart? Found it! This article shows what stacked charts are &amp; how to easily build such data visualizations using JS.\" \/>\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\/2022\/04\/12\/stacked-chart\/\" \/>\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 Chart with JavaScript\" \/>\n<meta property=\"og:description\" content=\"Learn what a stacked chart is and how to easily create stacked charts of various types using JS, with Beijing 2022 medal counts visualized.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/\" \/>\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=\"2022-04-12T07:41:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-13T11:10:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-social.png\" \/>\n<meta name=\"author\" content=\"Shachee Swadia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"How to Create Stacked Chart with JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"Learn what a stacked chart is and how to easily create stacked charts of various types using JS, with Beijing 2022 medal counts visualized.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-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=\"Shachee Swadia\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"How to Create Stacked Chart with JavaScript\",\"datePublished\":\"2022-04-12T07:41:47+00:00\",\"dateModified\":\"2022-08-13T11:10:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/\"},\"wordCount\":2126,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart.png\",\"keywords\":[\"analysis\",\"analytics\",\"AnyChart\",\"app development\",\"bar chart\",\"bar charts\",\"Beijing\",\"Beijing 2022\",\"Beijing 2022 country standings\",\"Beijing 2022 medal counts\",\"Beijing 2022 Olympics\",\"best data visualization examples\",\"best data visualizations\",\"chart design\",\"chart development\",\"chart examples\",\"chart types\",\"charts\",\"column chart\",\"column charts\",\"dashboard design\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data design\",\"data science\",\"data stories\",\"data visual\",\"data visualisation\",\"Data Visualization\",\"data visualization best practices\",\"data visualization design\",\"data visualization development\",\"data visualization examples\",\"data visualization practice\",\"data visualization projects\",\"data visualization techniques\",\"data visualization tool\",\"data visualization tutorial\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"dataviz examples\",\"example\",\"front-end development\",\"guest post\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"html5 dashboards\",\"infographic\",\"infographics\",\"interactive charts\",\"interactive dashboard\",\"interactive data visualization\",\"interactive graphics\",\"interactive html5 dashboard\",\"interactive infographic\",\"interactive infographics\",\"interactive javascript dashboard\",\"interactive visualizations\",\"interactivity\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"javascript charting api\",\"JavaScript charting features\",\"JavaScript charting library\",\"javascript charts\",\"javascript dashboards\",\"javascript graph\",\"javascript graphics\",\"JavaScript library\",\"javascript technologies\",\"js chart\",\"js charting\",\"js dashboards\",\"JS graphics\",\"medal count charts\",\"Olympic Games\",\"Olympic medal count\",\"Olympics\",\"Olympics country standings\",\"percent stacked area chart\",\"percent stacked bar chart\",\"percent stacked chart\",\"Smashing Magazine\",\"sports\",\"sports data visualization\",\"stacked area chart\",\"stacked area charts\",\"stacked bar chart\",\"stacked bar charts\",\"stacked charts\",\"stacked column charts\",\"statistical analysis\",\"statistics\",\"Tips and tricks\",\"tutorial\",\"visual analysis\",\"visual analytics\",\"visual data analytics\",\"visualization\",\"visualization techniques\",\"visualizations\",\"web analytics\",\"web charts\",\"web design\",\"web developers\",\"web development\",\"Winter Olympics\"],\"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\/2022\/04\/12\/stacked-chart\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/\",\"name\":\"Stacked Chart: Definition, Types & How to Create It with JavaScript\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart.png\",\"datePublished\":\"2022-04-12T07:41:47+00:00\",\"dateModified\":\"2022-08-13T11:10:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"Looking for information on a stacked chart? Found it! This article shows what stacked charts are & how to easily build such data visualizations using JS.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart.png\",\"width\":1800,\"height\":1000},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Stacked 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\/273255f98371177b5ac1f4775610bb51\",\"name\":\"Shachee Swadia\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g\",\"caption\":\"Shachee Swadia\"},\"url\":\"https:\/\/www.anychart.com\/blog\/author\/shachee-swadia\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Stacked Chart: Definition, Types & How to Create It with JavaScript","description":"Looking for information on a stacked chart? Found it! This article shows what stacked charts are & how to easily build such data visualizations using JS.","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\/2022\/04\/12\/stacked-chart\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Stacked Chart with JavaScript","og_description":"Learn what a stacked chart is and how to easily create stacked charts of various types using JS, with Beijing 2022 medal counts visualized.","og_url":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2022-04-12T07:41:47+00:00","article_modified_time":"2022-08-13T11:10:59+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-social.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"How to Create Stacked Chart with JavaScript","twitter_description":"Learn what a stacked chart is and how to easily create stacked charts of various types using JS, with Beijing 2022 medal counts visualized.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart-social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"How to Create Stacked Chart with JavaScript","datePublished":"2022-04-12T07:41:47+00:00","dateModified":"2022-08-13T11:10:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/"},"wordCount":2126,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart.png","keywords":["analysis","analytics","AnyChart","app development","bar chart","bar charts","Beijing","Beijing 2022","Beijing 2022 country standings","Beijing 2022 medal counts","Beijing 2022 Olympics","best data visualization examples","best data visualizations","chart design","chart development","chart examples","chart types","charts","column chart","column charts","dashboard design","data analysis","data analytics","data analytics examples","data design","data science","data stories","data visual","data visualisation","Data Visualization","data visualization best practices","data visualization design","data visualization development","data visualization examples","data visualization practice","data visualization projects","data visualization techniques","data visualization tool","data visualization tutorial","data visualizations","data visuals","data viz examples","dataviz examples","example","front-end development","guest post","HTML","HTML charts","HTML5","html5 charts","html5 dashboards","infographic","infographics","interactive charts","interactive dashboard","interactive data visualization","interactive graphics","interactive html5 dashboard","interactive infographic","interactive infographics","interactive javascript dashboard","interactive visualizations","interactivity","JavaScript","javascript chart tutorial","javascript charting","javascript charting api","JavaScript charting features","JavaScript charting library","javascript charts","javascript dashboards","javascript graph","javascript graphics","JavaScript library","javascript technologies","js chart","js charting","js dashboards","JS graphics","medal count charts","Olympic Games","Olympic medal count","Olympics","Olympics country standings","percent stacked area chart","percent stacked bar chart","percent stacked chart","Smashing Magazine","sports","sports data visualization","stacked area chart","stacked area charts","stacked bar chart","stacked bar charts","stacked charts","stacked column charts","statistical analysis","statistics","Tips and tricks","tutorial","visual analysis","visual analytics","visual data analytics","visualization","visualization techniques","visualizations","web analytics","web charts","web design","web developers","web development","Winter Olympics"],"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\/2022\/04\/12\/stacked-chart\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/","url":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/","name":"Stacked Chart: Definition, Types & How to Create It with JavaScript","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart.png","datePublished":"2022-04-12T07:41:47+00:00","dateModified":"2022-08-13T11:10:59+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"Looking for information on a stacked chart? Found it! This article shows what stacked charts are & how to easily build such data visualizations using JS.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/04\/stacked-chart.png","width":1800,"height":1000},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2022\/04\/12\/stacked-chart\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Stacked 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\/273255f98371177b5ac1f4775610bb51","name":"Shachee Swadia","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g","caption":"Shachee Swadia"},"url":"https:\/\/www.anychart.com\/blog\/author\/shachee-swadia\/"}]}},"_links":{"self":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14786","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\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/comments?post=14786"}],"version-history":[{"count":17,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14786\/revisions"}],"predecessor-version":[{"id":15527,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14786\/revisions\/15527"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=14786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=14786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=14786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}