{"id":14887,"date":"2022-05-12T15:34:11","date_gmt":"2022-05-12T15:34:11","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=14887"},"modified":"2022-08-13T11:11:17","modified_gmt":"2022-08-13T11:11:17","slug":"area-chart-js","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/","title":{"rendered":"Building Area Chart with JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart.png\" alt=\"\" width=\"100%\" class=\"alignnone size-full wp-image-14900\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart.png 1400w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart-300x167.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart-768x428.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart-1024x571.png 1024w\" sizes=\"(max-width: 1400px) 100vw, 1400px\" \/><\/a>If you are into <a href=\"https:\/\/www.anychart.com\/blog\/2018\/11\/20\/data-visualization-definition-history-examples\/\">data visualization<\/a>, one of the things that you might often need to do is represent a variable\u2019s values over time. Or, you might need to compare multiple datasets in terms of how they are changing during a certain period. This is where area charts can be helpful.<\/p>\n<p>Not sure how to build an elegant area chart? Now you will master a really easy way! In this step-by-step tutorial, we will be visualizing data on the military budgets of the USA and Russia over the past two decades in interactive area charts using JavaScript. All aboard!<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>What Is an Area Chart?<\/h2>\n<p>An area chart is a graphical representation of data that shows how numeric values of one or more datasets change relative to a second variable, which is typically the time.<\/p>\n<p>The area chart type was introduced by <a href=\"https:\/\/en.wikipedia.org\/wiki\/William_Playfair\" target=\"_blank\" rel=\"nofollow\">William Playfair<\/a> in 1786, who is also credited for the invention of line, bar, and pie charts. It consists of a line with the underlying area filled with a color. In multi-series area graphs, as you can imagine, there are several lines with shaded areas.<\/p>\n<h2>Area Chart That Will Be Created<\/h2>\n<p>In this tutorial, first, we will plot the military budget of the United States of America from the year 2000 to 2020. Then, we\u2019ll turn that single-series JS area chart into a multi-series by adding the same kind of data for the Russian Federation.<\/p>\n<p>Check out how the final JavaScript-based area chart will look, showing how many billions of dollars the two countries spent for defense purposes over the past two decades:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/7-area-chart-js-multi-series-final.png\" alt=\"\" width=\"100%\" class=\"alignnone size-full wp-image-14897\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/7-area-chart-js-multi-series-final.png 1136w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/7-area-chart-js-multi-series-final-300x171.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/7-area-chart-js-multi-series-final-768x437.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/7-area-chart-js-multi-series-final-1024x583.png 1024w\" sizes=\"(max-width: 1136px) 100vw, 1136px\" \/><\/p>\n<h2>How to Build a Basic JS Area Chart<\/h2>\n<p>Building an interactive area chart from scratch might be intimidating and time-consuming. But there are quite a few helpful <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">JavaScript charting libraries<\/a> that can be helpful. Actually, no matter exactly which one you use, the entire process of creating any JS-based chart, including our area graph, can be split into four fundamental steps:<\/p>\n<ol>\n<li>Create a basic web page in HTML.<\/li>\n<li>Add the required JavaScript files.<\/li>\n<li>Load the data.<\/li>\n<li>Write some JavaScript code to draw the chart.<\/li>\n<\/ol>\n<p>For an illustrative example in this tutorial, I opted for <a href=\"https:\/\/www.anychart.com\/\">AnyChart<\/a>. This JavaScript library looks not difficult to get started with as there are quite thorough <a href=\"https:\/\/docs.anychart.com\/\" target=\"_blank\" rel=\"nofollow\">documentation<\/a> and many <a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/\">examples<\/a>, and it\u2019s free for any non-commercial use.<\/p>\n<p>Although it\u2019s not necessary, some background knowledge of HTML, CSS, and JavaScript would help to understand the concepts faster. But no need to worry even if you are a complete beginner. We will go through each step in detail, and by the end of this tutorial, you will have learned to build a JS area chart even if you are a novice with limited coding experience.<\/p>\n<h3>1. Create a basic web page in HTML<\/h3>\n<p>The first thing we need to do is create a basic HTML page for our area chart. We give it the title of \u201cJavaScript Area Chart.\u201d<\/p>\n<p>On this page, we add an HTML block element, <code>&lt;div&gt;<\/code>. We give it a unique id attribute of \u201ccontainer\u201d so that we can reference it later in the code.<\/p>\n<p>We also add some CSS rules in the <code>&lt;style&gt;<\/code> block to display our chart over the entire screen and define the <code>width<\/code> and <code>height<\/code> properties as 100% and margin and padding as 0. Feel free to define all that as per your need.<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;meta charset=\"utf-8\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Area Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0height: 100%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0margin: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>2. Add the required JavaScript files<\/h3>\n<p>Next, we need to add the JavaScript files of the charting library in the <code>&lt;head&gt;<\/code> section. We can either download them locally or use a CDN (Content Delivery Network).<\/p>\n<p>For this tutorial, let\u2019s add the necessary script files from <a href=\"https:\/\/cdn.anychart.com\/\" target=\"_blank\" rel=\"nofollow\">AnyChart CDN<\/a>. AnyChart has a modular structure which makes it easy to only connect the chart types and features that we require at the moment, reducing the size of the running JavaScript code.<\/p>\n<p>For the area chart type, for example, we can include just one <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#base\" target=\"_blank\" rel=\"nofollow\">Base<\/a> module.<\/p>\n<p>Our HTML can now look something like this.<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;meta charset=\"utf-8\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Area Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-base.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0height: 100%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0margin: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>3. Load the data<\/h3>\n<p>As previously stated, we will visualize the military budget data and start with a JavaScript area chart for the United States. I found an appropriate dataset on <a href=\"https:\/\/www.statista.com\/statistics\/272473\/us-military-spending-from-2000-to-2012\/\" target=\"_blank\" rel=\"nofollow\">Statista<\/a>.<\/p>\n<p>In order to properly load the data into our chart, we create an <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Data_Sets#array_of_arrays\" target=\"_blank\" rel=\"nofollow\">array<\/a>, where each element of the array consists of two elements. The first one is the year, and the second one is the military budget of the USA in billion dollars.<\/p>\n<p>For example, in the year 2000, the military budget of the USA was 320.09 billion dollars. So, our first array becomes <code>[\"2000\", 320.09]<\/code>.<\/p>\n<pre><code class=\"javascript\">var dataSet = [\r\n  [\"2000\", 320.09],\r\n  [\"2001\", 331.81],\r\n  [\"2002\", 378.46],\r\n  [\"2003\", 440.53],\r\n  [\"2004\", 493],\r\n  [\"2005\", 533.2],\r\n  [\"2006\", 558.34],\r\n  [\"2007\", 589.59],\r\n  [\"2008\", 656.76],\r\n  [\"2009\", 705.92],\r\n  [\"2010\", 738.01],\r\n  [\"2011\", 752.29],\r\n  [\"2012\", 725.21],\r\n  [\"2013\", 679.23],\r\n  [\"2014\", 647.79],\r\n  [\"2015\", 633.83],\r\n  [\"2016\", 639.86],\r\n  [\"2017\", 646.75],\r\n  [\"2018\", 682.49],\r\n  [\"2019\", 731.75],\r\n  [\"2020\", 766.58]\r\n];<\/code><\/pre>\n<h3>4. Write some JavaScript code to draw the chart<\/h3>\n<p>Now, just a few lines of JavaScript code to get our area chat up and running.<\/p>\n<p>The first thing we do here is add the <code>anychart.onDocumentReady()<\/code> function, which will enclose the whole JavaScript code of the area chart. This ensures that the code will not be executed till the page is fully loaded.<\/p>\n<pre><code class=\"html\">&lt;script&gt;\r\n\r\n\u00a0\u00a0anychart.onDocumentReady(function () {\r\n\u00a0\u00a0\u00a0\u00a0\/\/ The area chart's code will be written here.\r\n\u00a0\u00a0});\r\n\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>Next, we add our data from Step 3.<\/p>\n<pre><code class=\"javascript\">anychart.onDocumentReady(function () {\r\n\r\nvar dataSet = [\r\n[\"2000\", 320.09],\r\n[\"2001\", 331.81],\r\n[\"2002\", 378.46],\r\n[\"2003\", 440.53],\r\n[\"2004\", 493],\r\n[\"2005\", 533.2],\r\n[\"2006\", 558.34],\r\n[\"2007\", 589.59],\r\n[\"2008\", 656.76],\r\n[\"2009\", 705.92],\r\n[\"2010\", 738.01],\r\n[\"2011\", 752.29],\r\n[\"2012\", 725.21],\r\n[\"2013\", 679.23],\r\n[\"2014\", 647.79],\r\n[\"2015\", 633.83],\r\n[\"2016\", 639.86],\r\n[\"2017\", 646.75],\r\n[\"2018\", 682.49],\r\n[\"2019\", 731.75],\r\n[\"2020\", 766.58]\r\n];\r\n\r\n});\r\n\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>Then, we create our chart specifying the chart type as \u201carea\u201d and add the data.<\/p>\n<pre><code class=\"javascript\">var chart = anychart.area();\r\nchart.data(dataSet);<\/code><\/pre>\n<p>Finally, we add a title, put the chart in the previously defined <code>&lt;div&gt;<\/code> container, and display it using the <code>draw<\/code> command.<\/p>\n<pre><code class=\"javascript\">chart.title(\"Military Budget of the USA\");\r\nchart.container(\"container\");\r\nchart.draw();<\/code><\/pre>\n<p>Eureka! Our area chart 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-dcAQZsCK\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/dcAQZsCK\/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-dcAQZsCK{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>The interactive version of this basic JavaScript area chart with the full code can be found on <a href=\"https:\/\/playground.anychart.com\/dcAQZsCK\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>. Feel free to play around with it.<\/p>\n<p>For your convenience, I put up the full code below.<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;meta charset=\"utf-8\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Area Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-base.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0height: 100%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0margin: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.onDocumentReady(function () {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add the data as an array\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var dataSet = [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2000\", 320.09],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2001\", 331.81],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2002\", 378.46],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2003\", 440.53],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2004\", 493],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2005\", 533.2],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2006\", 558.34],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2007\", 589.59],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2008\", 656.76],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2009\", 705.92],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2010\", 738.01],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2011\", 752.29],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2012\", 725.21],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2013\", 679.23],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2014\", 647.79],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2015\", 633.83],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2016\", 639.86],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2017\", 646.75],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2018\", 682.49],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2019\", 731.75],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2020\", 766.58]\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0];\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create an area chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var chart= anychart.area();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the chart title\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.title(\"Military Budget of the USA\");\r\n \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the container id for the chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.container(\"container\");\r\n \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ initiate drawing the chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.draw();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n    \r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<p>Actually, this is just a basic, single-series version of an area chart. Now, let\u2019s add a second series.<\/p>\n<h2>How to Create a Multi-Series JS Area Chart<\/h2>\n<p>Building a multi-series area chart with JavaScript is also not a big deal. For us, it will take only three simple steps to turn our single-series area chart into a multi-series one.<\/p>\n<h3>A. Add the data<\/h3>\n<p>First, let\u2019s add the data for Russia\u2019s military budget to our array. Again, we are using the dataset from <a href=\"https:\/\/www.statista.com\/statistics\/1203160\/military-expenditure-russia\/\" target=\"_blank\" rel=\"nofollow\">Statista<\/a>. Now, each line will consist of three elements: the year, the value for the USA, and the value for Russia.<\/p>\n<p>For example, in the year 2000, the military budgets of the USA and Russia were 320.09 and 9.23 billion dollars, respectively. So, our first array becomes <code>[\"2000\", 320.09, 9.23]<\/code>.<\/p>\n<pre><code class=\"javascript\">var dataSet = [\r\n  [\"2000\", 320.09, 9.23],\r\n  [\"2001\", 331.81, 11.68],\r\n  [\"2002\", 378.46, 13.94],\r\n  [\"2003\", 440.53, 16.97],\r\n  [\"2004\", 493, 20.96],\r\n  [\"2005\", 533.2, 27.34],\r\n  [\"2006\", 558.34, 34.52],\r\n  [\"2007\", 589.59, 43.53],\r\n  [\"2008\", 656.76, 56.18],\r\n  [\"2009\", 705.92, 51.53],\r\n  [\"2010\", 738.01, 58.72],\r\n  [\"2011\", 752.29, 70.24],\r\n  [\"2012\", 725.21, 81.47],\r\n  [\"2013\", 679.23, 88.35],\r\n  [\"2014\", 647.79, 84.7],\r\n  [\"2015\", 633.83, 66.42],\r\n  [\"2016\", 639.86, 69.25],\r\n  [\"2017\", 646.75, 66.53],\r\n  [\"2018\", 682.49, 61.39],\r\n  [\"2019\", 731.75, 65.1],\r\n  [\"2020\", 766.58, 61.71]\r\n];<\/code><\/pre>\n<h3>B. Map the data<\/h3>\n<p>Second, let\u2019s make use of the handy <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Data_Sets\" target=\"_blank\" rel=\"nofollow\">Data Sets<\/a> feature of AnyChart: We will create a dataset from the data and then map it for each series:<\/p>\n<pre><code class=\"javascript\">var chart = anychart.area(); \r\n \r\nvar seriesData_1 = budgetData.mapAs({ x: 0, value: 1 });\r\nvar seriesData_2 = budgetData.mapAs({ x: 0, value: 2 });<\/code><\/pre>\n<h3>C. Configure the series<\/h3>\n<p>Finally, we create the series with the mapped data and also give them names.<\/p>\n<pre><code class=\"javascript\">var series1= chart.area(seriesData_1);\r\nseries1.name(\"USA\");\r\n\r\nvar series2= chart.area(seriesData_2);\r\nseries2.name(\"Russia\");<\/code><\/pre>\n<p>That\u2019s it, a cool JavaScript-based multi-series area chart is ready, providing an over-time view of the military budget of the USA along with Russia\u2019s on the same plot.<\/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-uFrTxGlp\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/uFrTxGlp\/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-uFrTxGlp{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>Explore its full code on <a href=\"https:\/\/playground.anychart.com\/uFrTxGlp\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.<\/p>\n<p>Our area chart is already looking good. But sometimes, good is not enough. And, there are times when you might need to tweak the functionalities and aesthetics of a chart. So now, let\u2019s do more and see how you can customize such graphs to make them look even better.<\/p>\n<h2>How to Customize a JavaScript Area Chart<\/h2>\n<p>Luckily the JavaScript charts powered by AnyChart can be modified to suit your needs and preferences very easily.<\/p>\n<p>I will show you how to do a few quick customizations to enhance our chart: fine-tune the X-scale, add a crosshair, change the color of areas, add a legend and axes titles, and configure the hover mode.<\/p>\n<h3>Fine-tune the X-scale<\/h3>\n<p>It will be great to begin with one quick adjustment \u2014 get rid of the gaps to the right and left of the area. We simply set the \u201ccontinuous\u201d mode for the X-scale.<\/p>\n<pre><code class=\"javascript\">chart.xScale().mode('continuous');<\/code><\/pre>\n<h3>Add a crosshair<\/h3>\n<p>Crosshairs are helpful in quickly understanding the X and Y values of a hovered data point. In our case, let\u2019s leave a vertical crosshair line only.<\/p>\n<pre><code class=\"javascript\">var crosshair = chart.crosshair();\r\ncrosshair.enabled(true)\r\n  .yStroke(null)\r\n  .xStroke('#fff');\r\ncrosshair.yLabel().enabled(false);<\/code><\/pre>\n<p>Just a few lines of JS code, and there is our crosshair, which makes the area chart more aesthetic.<\/p>\n<h3>Change the color of areas<\/h3>\n<p>According to a study I remember, every four people in a group of ten have blue as their favorite color. But it doesn\u2019t mean that we are going to leave the color of our chart as is, which is blue by default.<\/p>\n<p>Let\u2019s paint the USA series in red color and the Russia one in brown.<\/p>\n<pre><code class=\"javascript\">series1.fill(\"#AC2132\", 0.7);\r\n  .stroke(\"#AC2132\", 1);\r\n\r\nseries2.fill(\"#DEC081\", 0.7)\r\n  .stroke(\"#DEC081\", 1);<\/code><\/pre>\n<p>Here, we\u2019ve added the <code>fill<\/code> and <code>stroke<\/code> methods to change the colors of our area chart. There are also many other <a href=\"https:\/\/docs.anychart.com\/Appearance_Settings\" target=\"_blank\" rel=\"nofollow\">appearance settings<\/a> that can be applied to different <a href=\"https:\/\/docs.anychart.com\/Common_Settings\/Interactivity\/States\" target=\"_blank\" rel=\"nofollow\">states<\/a> of your visualization.<\/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-FfFrlNXs\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/FfFrlNXs\/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-FfFrlNXs{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>The interactive version of this area chart is available on <a href=\"https:\/\/playground.anychart.com\/FfFrlNXs\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>. Feel free to change the colors and see: <em>\u201cButterfly, butterfly, which color do you like?\u201d<\/em><\/p>\n<h3>Add a legend and axes titles<\/h3>\n<p>We can add a legend for our JavaScript area chart with a single line of code.<\/p>\n<pre><code class=\"javascript\">chart.legend(true);<\/code><\/pre>\n<p>Similarly, we can easily provide the axes with titles. In our chart, there are years on the X-axis, and on the Y-axis, there are the military budget figures in billion dollars.<\/p>\n<pre><code class=\"javascript\">chart.xAxis().title(\"Year\");\r\nchart.yAxis().title(\"Billions of USD\");<\/code><\/pre>\n<p>This is how our JS-based area chart looks now, with the legend and axes titles.<\/p>\n<h3>Configure the hover mode<\/h3>\n<p>Currently, when we hover over the chart, both series\u2019 data points for the corresponding year are highlighted with a marker. But what if we want to separate them?<\/p>\n<p>Let\u2019s enable the \u201csingle\u201d hover mode, and then when you hover over on an area, only markers on that particular series will be shown.<\/p>\n<pre><code class=\"javascript\">chart.interactivity().hoverMode(\"single\");<\/code><\/pre>\n<p>While we are in the \u201csingle\u201d hover mode, the crosshair doesn\u2019t make much sense. So, for configuring the hover mode, we can either remove or comment out the code that we wrote in the \u201cAdd a crosshair\u201d section of this tutorial.<\/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-XzGpeUU6\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/XzGpeUU6\/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-XzGpeUU6{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>Check out the whole code of this final interactive JavaScript area chart below, and also on <a href=\"https:\/\/playground.anychart.com\/XzGpeUU6\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>. Feel free to try some experimentation with it.<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;meta charset=\"utf-8\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Area Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-cartesian.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0height: 100%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0margin: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.onDocumentReady(function () {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add the data as an array\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var dataSet = [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2000\", 320.09, 9.23],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2001\", 331.81, 11.68],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2002\", 378.46, 13.94],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2003\", 440.53, 16.97],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2004\", 493, 20.96],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2005\", 533.2, 27.34],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2006\", 558.34, 34.52],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2007\", 589.59, 43.53],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2008\", 656.76, 56.18],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2009\", 705.92, 51.53],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2010\", 738.01, 58.72],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2011\", 752.29, 70.24],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2012\", 725.21, 81.47],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2013\", 679.23, 88.35],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2014\", 647.79, 84.7],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2015\", 633.83, 66.42],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2016\", 639.86, 69.25],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2017\", 646.75, 66.53],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2018\", 682.49, 61.39],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2019\", 731.75, 65.1],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[\"2020\", 766.58, 61.71]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0];\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create an area chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var chart= anychart.area();\r\n \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create a dataset for mapping\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var budgetData = anychart.data.set(dataSet);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ map the data\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var seriesData_1 = budgetData.mapAs({ x: 0, value: 1 });\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var seriesData_2 = budgetData.mapAs({ x: 0, value: 2 });\r\n \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create the first series, set the data and name\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var series1= chart.area(seriesData_1);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0series1.name(\"USA\");\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create the second series, set the data and name\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var series2= chart.area(seriesData_2);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0series2.name(\"Russia\");\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the chart title\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.title(\"Military Budget of the USA and Russia\");\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add and configure the crosshair\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ var crosshair = chart.crosshair();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ crosshair.enabled(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/   .yStroke(null)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/   .xStroke('#fff');\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ crosshair.yLabel().enabled(false);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ configure the visual settings of the first series\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0series1.fill(\"#AC2132\", 0.7);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.stroke(\"#AC2132\", 1);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ configure the visual settings of the second series\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0series2.fill(\"#DEC081\", 0.7)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.stroke(\"#DEC081\", 1);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add the legend\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.legend(true);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the titles of the axes\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.xAxis().title(\"Year\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.yAxis().title(\"Billions of US $\");\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the hover mode as single\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.interactivity().hoverMode(\"single\");\r\n \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the container id for the chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.container(\"container\");\r\n \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ initiate drawing the chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.draw();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>Awesome! We have built our JavaScript area chart. And the process has been simple, hasn\u2019t it? Go ahead and build your own JS-based area chart visualization.<\/p>\n<p>Please don\u2019t hesitate to look at the <a href=\"https:\/\/docs.anychart.com\/Basic_Charts\/Area_Chart\" target=\"_blank\" rel=\"nofollow\">area chart documentation<\/a>, and there are tons of other <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Supported_Charts_Types\" target=\"_blank\" rel=\"nofollow\">chart types<\/a> that you might like to check out.<\/p>\n<p>At last, feel free to ask me any questions or drop a suggestion. Can\u2019t wait to see the JavaScript area chart you will build.<\/p>\n<hr \/>\n<p><em>Published with the permission of Awan Shrestha. Originally appeared on <a href=\"https:\/\/levelup.gitconnected.com\/building-area-charts-with-javascript-580891398e0\" target=\"_blank\" rel=\"nofollow\">Level Up Coding<\/a> with the title <em>&#8220;Building Area Charts with JavaScript&#8221;<\/em> on May 10, 2022.<\/p>\n<p>You may also like to check out our own basic JavaScript <a href=\"https:\/\/www.anychart.com\/blog\/2017\/10\/28\/create-javascript-area-chart\/\">Area Chart Tutorial<\/a>.<\/p>\n<p>See more <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a>.<\/p>\n<p><a href=\"https:\/\/www.anychart.com\/support\/\">Let us know<\/a> if you want to contribute an awesome guest post.<\/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>If you are into data visualization, one of the things that you might often need to do is represent a variable\u2019s values over time. Or, you might need to compare multiple datasets in terms of how they are changing during a certain period. This is where area charts can be helpful. Not sure how to [&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":22,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,23,13,279,4],"tags":[53,3173,72,73,3211,1758,3149,284,127,166,258,471,266,620,1759,3352,509,195,2220,54,1389,256,1111,744,3032,1379,165,313,1370,133,774,775,3369,1498,805,95,1762,2013,2014,32,55,1335,144,167,146,433,152,2949,151,36,907,141,249,81,57,1238,142,96,99,134,58,65,56,2640,3368,601,3350,459,2844,30,3367,172,309,954,293,2015,2816,1763,804],"class_list":["post-14887","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-app-development","tag-area-chart","tag-area-charts","tag-area-graph","tag-chart-design","tag-chart-development","tag-chart-examples","tag-chart-types","tag-charting","tag-charts","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-design","tag-data-graphic","tag-data-graphics","tag-data-over-time","tag-data-visual","tag-data-visualization","tag-data-visualization-best-pracices","tag-data-visualization-examples","tag-data-visualization-practice","tag-data-visualization-techniques","tag-data-visualization-technologies","tag-data-visualization-tool","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-dataviz","tag-dataviz-examples","tag-dataviz-projects","tag-developers","tag-example","tag-front-end-development","tag-graphics-library","tag-guest-post","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-infographic","tag-infographics","tag-interactive-charts","tag-interactive-data-visualization","tag-interactive-graphics","tag-interactive-infographic","tag-interactive-infographics","tag-interactive-visualizations","tag-javascript","tag-javascript-chart-tutorial","tag-javascript-charting","tag-javascript-charting-api","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-graph","tag-javascript-graphics","tag-javascript-graphics-library","tag-javascript-library","tag-javascript-technologies","tag-js-chart","tag-js-charting","tag-js-charts","tag-military","tag-military-budget","tag-russia","tag-special-military-operation","tag-statistics","tag-time-series-chart","tag-tips-and-tricks","tag-tuto","tag-tutorial","tag-united-states","tag-visual-data-analytics","tag-visualization","tag-web-charts","tag-web-design","tag-web-developers","tag-web-development","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Area Chart with JavaScript: Step-by-Step How-To Guide<\/title>\n<meta name=\"description\" content=\"Learn what an area chart is &amp; how to create area charts using JavaScript. In this tutorial, we visualize military budgets of the U.S. &amp; Russia in 2000-2020.\" \/>\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\/05\/12\/area-chart-js\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Create Area Charts with JavaScript\" \/>\n<meta property=\"og:description\" content=\"Learn what an area chart is &amp; how to create area charts using JS. In this tutorial, we visualize military budgets of the U.S. &amp; Russia.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/\" \/>\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-05-12T15:34:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-13T11:11:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart-social.png\" \/>\n<meta name=\"author\" content=\"Awan Shrestha\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"How To Create Area Charts with JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"Learn what an area chart is &amp; how to create area charts using JS. In this tutorial, we visualize military budgets of the U.S. &amp; Russia.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-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=\"Awan Shrestha\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 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\/05\/12\/area-chart-js\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/\"},\"author\":{\"name\":\"Awan Shrestha\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/3f107fdcb3fe326a63cd52812f5287c1\"},\"headline\":\"Building Area Chart with JavaScript\",\"datePublished\":\"2022-05-12T15:34:11+00:00\",\"dateModified\":\"2022-08-13T11:11:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/\"},\"wordCount\":1751,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart.png\",\"keywords\":[\"AnyChart\",\"app development\",\"area chart\",\"area charts\",\"area graph\",\"chart design\",\"chart development\",\"chart examples\",\"chart types\",\"charting\",\"charts\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data design\",\"data graphic\",\"data graphics\",\"data over time\",\"data visual\",\"Data Visualization\",\"data visualization best practices\",\"data visualization examples\",\"data visualization practice\",\"data visualization techniques\",\"data visualization technologies\",\"data visualization tool\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"dataviz\",\"dataviz examples\",\"dataviz projects\",\"developers\",\"example\",\"front-end development\",\"graphics library\",\"guest post\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"infographic\",\"infographics\",\"interactive charts\",\"interactive data visualization\",\"interactive graphics\",\"interactive infographic\",\"interactive infographics\",\"interactive visualizations\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"javascript charting api\",\"JavaScript charting library\",\"javascript charts\",\"javascript graph\",\"javascript graphics\",\"JavaScript graphics library\",\"JavaScript library\",\"javascript technologies\",\"js chart\",\"js charting\",\"js charts\",\"military\",\"military budget\",\"Russia\",\"special military operation\",\"statistics\",\"time-series-chart\",\"Tips and tricks\",\"tuto\",\"tutorial\",\"united states\",\"visual data analytics\",\"visualization\",\"web charts\",\"web design\",\"web developers\",\"web development\"],\"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\/05\/12\/area-chart-js\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/\",\"name\":\"Area Chart with JavaScript: Step-by-Step How-To Guide\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart.png\",\"datePublished\":\"2022-05-12T15:34:11+00:00\",\"dateModified\":\"2022-08-13T11:11:17+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/3f107fdcb3fe326a63cd52812f5287c1\"},\"description\":\"Learn what an area chart is & how to create area charts using JavaScript. In this tutorial, we visualize military budgets of the U.S. & Russia in 2000-2020.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart.png\",\"width\":1400,\"height\":780},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building 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\/3f107fdcb3fe326a63cd52812f5287c1\",\"name\":\"Awan Shrestha\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/02ebd18c927547ca82372246dddcc3aebfa98928cb91405eef1a63ece7f17518?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/02ebd18c927547ca82372246dddcc3aebfa98928cb91405eef1a63ece7f17518?s=96&r=g\",\"caption\":\"Awan Shrestha\"},\"url\":\"https:\/\/www.anychart.com\/blog\/author\/awan-shrestha\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Area Chart with JavaScript: Step-by-Step How-To Guide","description":"Learn what an area chart is & how to create area charts using JavaScript. In this tutorial, we visualize military budgets of the U.S. & Russia in 2000-2020.","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\/05\/12\/area-chart-js\/","og_locale":"en_US","og_type":"article","og_title":"How To Create Area Charts with JavaScript","og_description":"Learn what an area chart is & how to create area charts using JS. In this tutorial, we visualize military budgets of the U.S. & Russia.","og_url":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2022-05-12T15:34:11+00:00","article_modified_time":"2022-08-13T11:11:17+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart-social.png","type":"","width":"","height":""}],"author":"Awan Shrestha","twitter_card":"summary_large_image","twitter_title":"How To Create Area Charts with JavaScript","twitter_description":"Learn what an area chart is & how to create area charts using JS. In this tutorial, we visualize military budgets of the U.S. & Russia.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart-social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Awan Shrestha","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/"},"author":{"name":"Awan Shrestha","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/3f107fdcb3fe326a63cd52812f5287c1"},"headline":"Building Area Chart with JavaScript","datePublished":"2022-05-12T15:34:11+00:00","dateModified":"2022-08-13T11:11:17+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/"},"wordCount":1751,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart.png","keywords":["AnyChart","app development","area chart","area charts","area graph","chart design","chart development","chart examples","chart types","charting","charts","data analysis","data analytics","data analytics examples","data design","data graphic","data graphics","data over time","data visual","Data Visualization","data visualization best practices","data visualization examples","data visualization practice","data visualization techniques","data visualization technologies","data visualization tool","data visualizations","data visuals","data viz examples","dataviz","dataviz examples","dataviz projects","developers","example","front-end development","graphics library","guest post","HTML","HTML charts","HTML5","html5 charts","infographic","infographics","interactive charts","interactive data visualization","interactive graphics","interactive infographic","interactive infographics","interactive visualizations","JavaScript","javascript chart tutorial","javascript charting","javascript charting api","JavaScript charting library","javascript charts","javascript graph","javascript graphics","JavaScript graphics library","JavaScript library","javascript technologies","js chart","js charting","js charts","military","military budget","Russia","special military operation","statistics","time-series-chart","Tips and tricks","tuto","tutorial","united states","visual data analytics","visualization","web charts","web design","web developers","web development"],"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\/05\/12\/area-chart-js\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/","url":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/","name":"Area Chart with JavaScript: Step-by-Step How-To Guide","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart.png","datePublished":"2022-05-12T15:34:11+00:00","dateModified":"2022-08-13T11:11:17+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/3f107fdcb3fe326a63cd52812f5287c1"},"description":"Learn what an area chart is & how to create area charts using JavaScript. In this tutorial, we visualize military budgets of the U.S. & Russia in 2000-2020.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/area-chart.png","width":1400,"height":780},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/12\/area-chart-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Building 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\/3f107fdcb3fe326a63cd52812f5287c1","name":"Awan Shrestha","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/02ebd18c927547ca82372246dddcc3aebfa98928cb91405eef1a63ece7f17518?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/02ebd18c927547ca82372246dddcc3aebfa98928cb91405eef1a63ece7f17518?s=96&r=g","caption":"Awan Shrestha"},"url":"https:\/\/www.anychart.com\/blog\/author\/awan-shrestha\/"}]}},"_links":{"self":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14887","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\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/comments?post=14887"}],"version-history":[{"count":21,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14887\/revisions"}],"predecessor-version":[{"id":15528,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14887\/revisions\/15528"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=14887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=14887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=14887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}