{"id":10302,"date":"2020-05-06T06:19:30","date_gmt":"2020-05-06T06:19:30","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=10302"},"modified":"2022-08-13T10:58:50","modified_gmt":"2022-08-13T10:58:50","slug":"javascript-choropleth-map-tutorial","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/","title":{"rendered":"Creating Choropleth Map Data Visualization Using JavaScript, on COVID-19 Stats"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone size-full wp-image-10344\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png\" alt=\"Creating a choropleth map data visualization using JavaScript (JS HTML5)\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png 1400w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial-300x189.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial-768x485.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial-1024x647.png 1024w\" sizes=\"(max-width: 1400px) 100vw, 1400px\" \/>These days you see <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/choropleth-map\/\">choropleth maps<\/a> in a variety of webpages and utilized for various subjects. Have you wondered how such data visualizations are built? Are you interested in making them by yourself? If so, stay with me through this JS charting tutorial, where I will show you <strong>how\u00a0to\u00a0create an interactive JavaScript choropleth map<\/strong> from scratch but with ease.<\/p>\n<p>Basic\u00a0knowledge of HTML5 and\u00a0JS is always\u00a0helpful,\u00a0but even if you are a beginner in this field, understand these <strong>four simple steps<\/strong>\u00a0and you will be able to\u00a0quickly get\u00a0a good-looking cross-platform interactive choropleth map data visualization\u00a0for your app or website!<\/p>\n<p>What exactly are choropleth maps? When you break down the word, you see that <em>choro-<\/em> (\u201c<em>choros<\/em>\u201d) means \u201c<em>area<\/em>\u201d and <em>pleth-<\/em> (\u201c<em>plethos<\/em>\u201d) means \u201c<em>multitude<\/em>.\u201d Exactly, these maps are used to visualize statistical data related to multiple geographic areas. Each area is colored or shaded differently according to the value of the given data, making it easy to grasp how a measurement varies\u00a0across a territory.<\/p>\n<p>For this JS mapping tutorial, I will use open <strong>COVID-19 data<\/strong> to show the distribution of confirmed cases and deaths around the world by country. I will start with a basic choropleth map that will graphically represent the confirmed cases. Then I will add a legend, customize the tooltip, and add bubbles to visualize the number of deaths.<\/p>\n<p>Let\u2019s get started!<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>How to Create JavaScript Choropleth Map<\/h2>\n<p>Generally, building a JavaScript-based chart or map requires four basic things:<\/p>\n<ol>\n<li>Create the HTML page for your chart.<\/li>\n<li>Add the necessary JavaScript files.<\/li>\n<li>Prepare the data you want to visualize.<\/li>\n<li>Write the JS code for the chart.<\/li>\n<\/ol>\n<p>Now, let\u2019s look at each step in detail. Here is a choropleth map that will be the final output of the first part of this tutorial:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-10340\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/javascript-choropleth-map-to-create.png\" alt=\"\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/javascript-choropleth-map-to-create.png 1354w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/javascript-choropleth-map-to-create-300x170.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/javascript-choropleth-map-to-create-768x436.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/javascript-choropleth-map-to-create-1024x581.png 1024w\" sizes=\"(max-width: 1354px) 100vw, 1354px\" \/><\/p>\n<h3>Step 1: Create the HTML page for your map<\/h3>\n<p>The first thing you need to do is create a basic HTML page. Give it a title and create an HTML block element (for example, <code>&lt;div&gt;)<\/code> to place your map chart. To identify this <code>&lt;div&gt;<\/code> later in the code, you should also give it an id attribute of your choice. Here, I have used the value \u201ccontainer\u201d.<\/p>\n<p>So your\u00a0page\u00a0can\u00a0look like this:<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n  &lt;title&gt;Choropleth Map&lt;\/title&gt;\r\n  &lt;style&gt;\r\n    html,\r\n    body,\r\n    #container {\r\n      width: 100%;\r\n      height: 100%;\r\n      margin: 0;\r\n      padding: 0;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n  &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/code><\/pre>\n<p>Note that you can use CSS rules in the <code>&lt;style&gt;<\/code> block to define how you want your upcoming JavaScript choropleth map\u00a0to be placed. In this case, using &#8220;100%&#8221; in both <code>width<\/code> and <code>height<\/code> parameters will make the\u00a0visualization occupy the entire page.<\/p>\n<h3>Step 2. Add the necessary JavaScript files<\/h3>\n<p>Second, you should go to the <code>&lt;head&gt;<\/code> section and reference all the appropriate JS scripts you are going to use.<\/p>\n<p>To create\u00a0a choropleth map along this tutorial, I will use AnyChart\u2019s <a href=\"https:\/\/www.anychart.com\/products\/anymap\/overview\/\">AnyMap JS library<\/a> which, as its name suggests, is specifically designed to\u00a0produce maps. JavaScript charting libraries are very popular\u00a0nowadays; they provide\u00a0commonly needed functions out of the box to make the developing process simpler and faster. This specific library is lightweight, flexible, and easy to get started, particularly\u00a0thanks\u00a0to\u00a0a greatly written <a href=\"https:\/\/docs.anychart.com\/Maps\/Quick_Start\" target=\"_blank\" rel=\"nofollow\">documentation<\/a> and a lot of samples in the <a href=\"https:\/\/www.anychart.com\/products\/anymap\/gallery\/\">map gallery<\/a>.<\/p>\n<p>In this tutorial,\u00a0I will use the <a href=\"https:\/\/www.anychart.com\/download\/cdn\/\">CDN<\/a>, but keep in mind that you can\u00a0<a href=\"https:\/\/www.anychart.com\/download\/\">download<\/a> the scripts if you want.<\/p>\n<p>For the choropleth map that I have in mind, I will need the following <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules\" target=\"_blank\" rel=\"nofollow\">modules<\/a>:<\/p>\n<ul>\n<li><strong>Core<\/strong>, which is the the basic module needed in order to use any other module,<\/li>\n<li><strong>Geo Maps<\/strong>, which contains the necessary information to create\u00a0geo map charts, and<\/li>\n<li><strong>GeoData<\/strong>, which contains information about the geographic locations.<\/li>\n<\/ul>\n<p>Additionally, I will use\u00a0<a href=\"https:\/\/github.com\/proj4js\/proj4js\/\" target=\"_blank\" rel=\"nofollow\">Proj4js<\/a>, a free open-source JavaScript library that transforms point coordinates to geographic coordinates.<\/p>\n<p>Here is the HTML code for this section:<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n  &lt;title&gt;Choropleth Map&lt;\/title&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/js\/anychart-core.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/js\/anychart-map.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/geodata\/custom\/world\/world.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/proj4js\/2.3.15\/proj4.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;style&gt;\r\n    html,\r\n    body,\r\n    #container {\r\n      width: 100%;\r\n      height: 100%;\r\n      margin: 0;\r\n      padding: 0;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n  &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n  &lt;script&gt;\r\n    \/\/ The choropleth map code will be written here\r\n  &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>Step 3: Prepare the data you want to visualize<\/h3>\n<h4>Load the data<\/h4>\n<p>In the third step, add data. In light of the COVID-19 pandemic, I will\u00a0create\u00a0a JavaScript choropleth map that will visualize the current situation around the world using data from the European Center for Disease Prevention and Control (<a href=\"https:\/\/www.ecdc.europa.eu\/en\/publications-data\/download-todays-data-geographic-distribution-covid-19-cases-worldwide\" target=\"_blank\" rel=\"nofollow\">ECDC<\/a>). I have downloaded the JSON version and you can find it <a href=\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/choropleth-map-tutorial\/data.json\" target=\"_blank\" rel=\"nofollow\">here<\/a> (data as of April 14).<\/p>\n<p>It is easy to\u00a0load data from a JSON file\u00a0using\u00a0the <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Data_Adapter\/Overview\" target=\"_blank\" rel=\"nofollow\">Data Adapter<\/a> helper module of AnyChart, which should be added\u00a0to the <code>&lt;head&gt;<\/code>\u00a0section:<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n  &lt;title&gt;Choropleth Map&lt;\/title&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/js\/anychart-core.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/js\/anychart-map.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/geodata\/custom\/world\/world.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/proj4js\/2.3.15\/proj4.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;style&gt;\r\n    html,\r\n    body,\r\n    #container {\r\n      width: 100%;\r\n      height: 100%;\r\n      margin: 0;\r\n      padding: 0;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n  &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n  &lt;script&gt;\r\n    \/\/ The choropleth map code will be written here\r\n  &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/code><\/pre>\n<p>Now you can use the <a href=\"https:\/\/api.anychart.com\/anychart.data#loadJsonFile\" target=\"_blank\" rel=\"nofollow\">loadJsonFile<\/a> method provided by the Data Adapter to load JSON.<\/p>\n<pre><code class=\"javascript\">anychart.data.loadJsonFile (\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/choropleth-map-tutorial\/data.json\", function (data) {\r\n\r\n});<\/code><\/pre>\n<h4>Structure the data<\/h4>\n<p>The JSON data, which you have just loaded,\u00a0contains data per day for each country.<\/p>\n<p>There are two things you need to do here:<\/p>\n<ul>\n<li>Calculate the sum of all confirmed cases for each country.<\/li>\n<li>Structure the data in a format that will be recognizable by AnyChart. Specifically, I want to create an array that will have a region id and a value.<\/li>\n<\/ul>\n<p>To implement the above, you need to write some code. Here is the approach I will use to calculate and structure the data:<\/p>\n<p>I will read the JSON data and calculate the total confirmed cases for each country. As soon as I am done with one country, I will pass this info into an array that I have named \u201cdata\u201d and then I will continue with the next country.<\/p>\n<p>The array will use:<\/p>\n<ul>\n<li><code>id<\/code>: the geographic identifier for the country<\/li>\n<li><code>value<\/code>: the number of total confirmed cases for the country<\/li>\n<li><code>title<\/code>: the name of the country<\/li>\n<\/ul>\n<p>Here is the code for this section:<\/p>\n<pre><code class=\"javascript\">anychart.data.loadJsonFile (\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/choropleth-map-tutorial\/data.json\", function (data) {\r\n\r\n  \/\/ Variables\r\n  \/\/ go into the records section of the data\r\n  var geoData = data.records\r\n\r\n  \/\/ sum of all cases per country\r\n  var sumCases = 0;\r\n\r\n  \/\/ convert cases to numbers\r\n  var numC;\r\n\r\n  \/\/ create a new array with the resulting data\r\n  var data = [];\r\n\r\n  \/\/ Go through the initial data\r\n  for (var i = 0; i &lt; geoData.length; i++) {\r\n    \/\/ convert strings to numbers and save them to new variables\r\n    numC = parseInt(geoData[i].cases);\r\n\r\n    \/\/ check if we are in the same country by comparing the geoId. \r\n    \/\/ if the country is the same add the cases to the appropriate variables\r\n    if ((geoData[i + 1]) != null &amp;&amp; (geoData[i].geoId == geoData[i + 1].geoId)) {\r\n      sumCases = sumCases + numC;\r\n    }\r\n    else {\r\n      \/\/ add last day cases of the same country\r\n      sumCases = sumCases + numC;\r\n\r\n      \/\/ insert the resulting data in the array using the AnyChart keywords \r\n      data.push({ id: geoData[i].geoId, value: sumCases, title: geoData[i].countriesAndTerritories })\r\n\r\n      \/\/ reset the variables to start over\r\n      sumCases = 0;\r\n                        \r\n    }\r\n  };\r\n});\r\n<\/code><\/pre>\n<h4>Map the data<\/h4>\n<p>The final part of this step consists in connecting the resulting data with the geographic map. Just add the following two lines of the code and it will be completed:<\/p>\n<pre><code class=\"javascript\">var chart = anychart.map(data);\r\nchart.geoData(anychart.maps.world);<\/code><\/pre>\n<h3>Step 4: Write the JS code for the chart<\/h3>\n<p>Finally, write some JavaScript code to develop the JS choropleth map itself!<\/p>\n<p>Remember that everything should be placed inside the <code>&lt;script&gt;<\/code> tag.\u00a0You\u00a0need to enclose the code inside the <code>anychart.onDocumentReady<\/code> function that is executed when the page is ready.<\/p>\n<pre><code class=\"html\">&lt;script&gt;\r\n  anychart.onDocumentReady(function () {\r\n    \/\/ The choropleth map code will be written here\r\n  });\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>Data needs to be placed inside of this function, so let\u2019s take the code from step 3 and put it here, to start with:<\/p>\n<pre><code class=\"html\">&lt;script&gt;\r\nanychart.onDocumentReady(function () {\r\n  \/\/ The choropleth map code will be written here\r\n  anychart.data.loadJsonFile (\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/choropleth-map-tutorial\/data.json\", function (data) {\r\n\r\n  \/\/ Variables\r\n  \/\/ go into the records section of the data\r\n  var geoData = data.records\r\n\r\n  \/\/ sum of all cases per country\r\n  var sumCases = 0;\r\n\r\n  \/\/ convert cases to numbers\r\n  var numC;\r\n\r\n  \/\/ create a new array with the resulting data\r\n  var data = [];\r\n\r\n  \/\/ Go through the initial data\r\n  for (var i = 0; i &lt; geoData.length; i++) {\r\n    \/\/ convert strings to numbers and save them to new variables\r\n    numC = parseInt(geoData[i].cases);\r\n\r\n    \/\/ check if we are in the same country by comparing the geoId.\r\n    \/\/ if the country is the same add the cases to the appropriate variables\r\n    if ((geoData[i + 1]) != null &amp;&amp; (geoData[i].geoId == geoData[i + 1].geoId)) {\r\n      sumCases = sumCases + numC;\r\n    }\r\n    else {\r\n\r\n      \/\/ add last day cases of the same country\r\n      sumCases = sumCases + numC;\r\n\r\n      \/\/ insert the resulting data in the array using the AnyChart keywords \r\n      data.push({ id: geoData[i].geoId, value: sumCases, title: geoData[i].countriesAndTerritories })\r\n\r\n      \/\/ reset the variables to start over\r\n      sumCases = 0;\r\n\r\n    }\r\n<\/code><code class=\"html\">  };<\/code><\/pre>\n<pre><code class=\"html\">  \/\/ connect the data with the map\r\n  var chart = anychart.map(data); chart.geoData(anychart.maps.world);\r\n\r\n});\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>Finally, let&#8217;s set everything else, coloring each country according to the value of the total number of confirmed cases. First, I will specify the chart type,\u00a0create\u00a0the\u00a0series, and\u00a0add an appropriate title. Second, I will create a <a href=\"https:\/\/docs.anychart.com\/Maps\/Scales\" target=\"_blank\" rel=\"nofollow\">color scale<\/a> and apply it to the chart. Look:<\/p>\n<pre><code class=\"javascript\">\/\/ specify the chart type and set the series \r\nvar series = chart.choropleth(data);\r\n        \r\n\/\/ set the chart title\r\nchart.title(\"COVID-19 Global Cases\");\r\n\r\n\/\/ color scale ranges\r\nocs = anychart.scales.ordinalColor([\r\n  { less: 99 },\r\n  { from: 100, to: 999 },\r\n  { from: 1000, to: 9999 },\r\n  { from: 10000, to: 29999 },\r\n  { from: 30000, to: 39000 },\r\n  { from: 40000, to: 59000 },\r\n  { from: 60000, to: 99999 },\r\n  { greater: 100000 }\r\n]);\r\n        \r\n\/\/ set scale colors\r\nocs.colors([\"rgb(252,245,245)\", \"rgb(241,219,216)\",\"rgb(229,190,185)\", \"rgb(211,152,145)\", \"rgb(192,117,109)\", \"rgb(178,93,86)\", \"rgb(152,50,48)\", \"rgb(150,33,31)\"]);\r\n\r\n\/\/ tell the series what to use as a colorRange (colorScale)\r\nseries.colorScale(ocs);<\/code><\/pre>\n<p>Then, command to draw the map chart:<\/p>\n<pre><code class=\"html\">\/\/ set the container id\r\nchart.container('container');\r\n\r\n\/\/ draw the chart\r\nchart.draw();<\/code><\/pre>\n<p>Here is the result:<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-efdxRDjm\" src=\"https:\/\/playground.anychart.com\/efdxRDjm\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-efdxRDjm{width:100%;height:500px;}\");\n})();<\/script><\/p>\n<p>The resulting JS choropleth map, embedded from <a href=\"https:\/\/playground.anychart.com\/efdxRDjm\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>, gives a concise visualization of how COVID-19 has affected each country. You can hover over areas to see the name and the number of confirmed cases, for each country. Everyone can read such a geographic data visualization with ease.<\/p>\n<p>The\u00a0full code of the choropleth map just built using JavaScript\/HTML5 is below:<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n  &lt;title&gt;Choropleth Map&lt;\/title&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/js\/anychart-core.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/js\/anychart-map.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/geodata\/custom\/world\/world.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/proj4js\/2.3.15\/proj4.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;\r\n\r\n  &lt;style&gt;&gt;\r\n    html,\r\n    body,\r\n    #container {\r\n      width: 100%;\r\n      height: 100%;\r\n      margin: 0;\r\n      padding: 0;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n  &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n  &lt;script&gt;\r\n\r\n    anychart.onDocumentReady(function () {\r\n\r\n      \/\/ load the data\r\n      anychart.data.loadJsonFile(\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/choropleth-map-tutorial\/data.json\", function (data) {\r\n\r\n        \/\/ Variables\r\n        \/\/ go into the records section of the data\r\n        var geoData = data.records\r\n\r\n        \/\/ sum of all cases per country\r\n        var sumCases = 0;\r\n\r\n        \/\/ convert cases to numbers\r\n        var numC;\r\n\r\n        \/\/ create a new array with the resulting data\r\n        var data = [];\r\n\r\n        \/\/ Go through the initial data\r\n        for (var i = 0; i &lt; geoData.length; i++) {\r\n          \/\/ convert strings to numbers and save them to new variables\r\n          numC = parseInt(geoData[i].cases);\r\n\r\n          \/\/ check if we are in the same country by comparing the geoId. \r\n          \/\/ if the country is the same add the cases to the appropriate variables\r\n          if ((geoData[i + 1]) != null &amp;&amp; (geoData[i].geoId == geoData[i + 1].geoId)) {\r\n            sumCases = sumCases + numC;\r\n          }\r\n          else {\r\n\r\n            \/\/ add last day cases of the same country\r\n            sumCases = sumCases + numC;\r\n\r\n            \/\/ insert the resulting data in the array using the AnyChart keywords \r\n            data.push({ id: geoData[i].geoId, value: sumCases, title: geoData[i].countriesAndTerritories })\r\n\r\n            \/\/ reset the variables to start over\r\n            sumCases = 0;\r\n\r\n          }\r\n        };\r\n\r\n        \/\/ connect the data with the map\r\n        var chart = anychart.map(data);\r\n        chart.geoData(anychart.maps.world);\r\n\r\n        \/\/ specify the chart type and set the series \r\n        var series = chart.choropleth(data);\r\n\r\n        \/\/ set the chart title\r\n        chart.title(\"COVID-19 Global Cases\");\r\n\r\n        \/\/ color scale ranges\r\n        ocs = anychart.scales.ordinalColor([\r\n          { less: 99 },\r\n          { from: 100, to: 999 },\r\n          { from: 1000, to: 9999 },\r\n          { from: 10000, to: 29999 },\r\n          { from: 30000, to: 39000 },\r\n          { from: 40000, to: 59000 },\r\n          { from: 60000, to: 99999 },\r\n          { greater: 100000 }\r\n        ]);\r\n\r\n        \/\/ set scale colors\r\n        ocs.colors([\"rgb(252,245,245)\", \"rgb(241,219,216)\", \"rgb(229,190,185)\", \"rgb(211,152,145)\", \"rgb(192,117,109)\", \"rgb(178,93,86)\", \"rgb(152,50,48)\", \"rgb(150,33,31)\"]);\r\n\r\n        \/\/ tell the series what to use as a colorRange (colorScale)\r\n        series.colorScale(ocs);\r\n\r\n        \/\/ set the container id\r\n        chart.container('container');\r\n        \r\n        \/\/ draw the chart\r\n        chart.draw();\r\n      });\r\n\r\n    });\r\n  &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>JS Choropleth Map Customization<\/h2>\n<p>You already have a wonderful and fully functional JavaScript choropleth map.\u00a0But what if you want to change some things or add some further functionality?<\/p>\n<p>AnyChart is a very flexible JS charting library.\u00a0So you can easily include modifications that are specific for your needs.<\/p>\n<p>Right now I will show you how to implement the following changes:<\/p>\n<ul>\n<li>Add a legend to the chart<\/li>\n<li>Add bubbles for graphical representation of the number of deaths<\/li>\n<li>Configure the tooltip<\/li>\n<\/ul>\n<p>In the end, I will get the following picture:<br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-10339\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-customized-final.png\" alt=\"\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-customized-final.png 1366w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-customized-final-300x156.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-customized-final-768x399.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-customized-final-1024x531.png 1024w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<h3>Add a legend to the chart<\/h3>\n<p>As a general rule for data visualization, every time you utilize\u00a0a color scale, you should include an explanation of what each color represents\u00a0somewhere on the page<\/p>\n<p>Using AnyChart, you can create a legend just by adding <code>chart.legend(true);<\/code>.<\/p>\n<p>In this case, because\u00a0the choropleth map has\u00a0only one series, you will need to have the involved categories represented in the legend.<\/p>\n<p>Here&#8217;s the\u00a0code for adding a legend to the JS choropleth map created above:<\/p>\n<pre><code class=\"javascript\">\/\/ enable the legend\r\nchart.legend(true);\r\n\r\n\/\/ set the source mode of the legend\r\nchart.legend().itemsSourceMode(\"categories\");<\/code><\/pre>\n<p>That\u2019s functional, but for aesthetic reasons I want the legend to appear on the right-hand side of the chart and to be aligned vertically. To do that, I will just add\u00a0some CSS rules:<\/p>\n<pre><code class=\"javascript\">\/\/ enable the legend\r\nchart.legend(true);\r\n\r\n\/\/ set the source mode of the legend and add styles\r\nchart.legend()\r\n  .itemsSourceMode(\"categories\") \r\n  .position('right')\r\n  .align('top')\r\n  .itemsLayout('vertical')\r\n  .padding(50, 0, 0, 20)\r\n  .paginator(false);<\/code><\/pre>\n<p>Here is the result (available on <a href=\"https:\/\/playground.anychart.com\/RjPyoq2W\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a> with the full code):<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-RjPyoq2W\" src=\"https:\/\/playground.anychart.com\/RjPyoq2W\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-RjPyoq2W{width:100%;height:500px;}\");\n})();<\/script><\/p>\n<h3>Add bubbles that will represent the number of deaths<\/h3>\n<p>Inspired by the\u00a0<a href=\"https:\/\/www.arcgis.com\/apps\/opsdashboard\/index.html#\/bda7594740fd40299423467b48e9ecf6\" target=\"_blank\" rel=\"nofollow\">visualization<\/a>\u00a0created by the Center for Systems Science and Engineering (CSSE) at Johns Hopkins University, I decided to depict the number of deaths using bubbles.<\/p>\n<p>First,\u00a0the total number of COVID-19 deaths for each country needs to be stored in the data alongside the total number of COVID-19 cases:<\/p>\n<pre><code class=\"javascript\">\/\/ sum of all cases per country\r\nvar sumCases = 0;\r\n\r\n\/\/ sum of all deaths per country\r\nvar sumDeaths = 0;\r\n\r\n\/\/ convert cases and deaths to numbers\r\nvar numC;\r\nvar numD;\r\n\r\n\/\/ create a new array with the resulting data\r\nvar data = [];\r\n\r\n\/\/ Go through the initial data\r\nfor (var i = 0; i &lt; geoData.length; i++) {\r\n  \/\/ convert strings to numbers and save them to new variables\r\n  numC = parseInt(geoData[i].cases);\r\n  numD = parseInt(geoData[i].deaths);\r\n\r\n  \/\/ check if we are in the same country by comparing the geoId\r\n  \/\/ if the country is the same, add cases and deaths to the appropriate variables\r\n  if ((geoData[i + 1]) != null &amp;&amp; (geoData[i].geoId == geoData[i + 1].geoId)) {\r\n    sumCases = sumCases + numC;\r\n    sumDeaths = sumDeaths + numD;\r\n  }\r\n  else {\r\n\r\n    \/\/ add last day cases and deaths of the same country\r\n    sumCases = sumCases + numC;\r\n    sumDeaths = sumDeaths + numD;\r\n\r\n    \/\/ insert the resulting data in the array using the AnyChart keywords \r\n    data.push({ id: geoData[i].geoId, value: sumCases, size: sumDeaths, title: geoData[i].countriesAndTerritories })\r\n\r\n    \/\/ reset the variables to start over\r\n    sumCases = 0;\r\n    sumDeaths = 0;\r\n\r\n  }\r\n};\r\n<\/code><\/pre>\n<p>Second,\u00a0store only the countries that have at least one death in a separate array:<\/p>\n<pre><code class=\"javascript\">\/\/ variable to store data that will be used for bubbles\r\nvar bubbleData=[];\r\n\r\n\/\/ store only the countries that have at least 1 death\r\nfor (var i=0; i&lt;data.length; i++) {\r\n  if (data[i].size&gt;0){\r\n    bubbleData.push(data[i]);\r\n  }\r\n};<\/code><\/pre>\n<p>Then, add the following JS code to create the bubble series on top of the choropleth series on the map.<\/p>\n<pre><code class=\"javascript\">\/\/ create a series for bubbles\r\nvar series_1 = chart.bubble(bubbleData);<\/code><\/pre>\n<p>Take a look at the map below or on <a href=\"https:\/\/playground.anychart.com\/t0kTUilD\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>:<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-t0kTUilD\" src=\"https:\/\/playground.anychart.com\/t0kTUilD\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-t0kTUilD{width:100%;height:500px;}\");\n})();<\/script><\/p>\n<p>It is a good idea to customize the size of the bubbles so that they don\u2019t\u00a0occupy\u00a0so much space on the plot. To do this, use AnyChart\u2019s <code>maxBubbleSize()<\/code> and <code>minBubbleSize()<\/code> functions. For example, like this:<\/p>\n<pre><code class=\"javascript\">\/\/ set the maximum size of the bubble\r\nchart.maxBubbleSize(25);\r\n\r\n\/\/ set the minimum size of the bubble\r\nchart.minBubbleSize(3);<\/code><\/pre>\n<p>Next, you can modify the color and stroke of the bubbles to make them more consistent with the rest of the chart:<\/p>\n<pre><code class=\"javascript\">\/\/ set colors and stroke of bubbles\r\nseries_1.normal().fill(\"black\", 0.3);\r\nseries_1.hovered().fill(\"black\", 0.1);\r\nseries_1.selected().fill(\"black\", 0.5);\r\nseries_1.normal().stroke(\"rgb(150,33,31)\");\r\nseries_1.hovered().stroke(\"rgb(150,33,31)\", 2);\r\nseries_1.selected().stroke(\"rgb(150,33,31)\", 4);<\/code><\/pre>\n<p>Check out\u00a0the outcome after these modifications, below or on <a href=\"https:\/\/playground.anychart.com\/JC0ZB65r\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>:<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-JC0ZB65r\" src=\"https:\/\/playground.anychart.com\/JC0ZB65r\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-JC0ZB65r{width:100%;height:500px;}\");\n})();<\/script><\/p>\n<h3>Configure the choropleth map tooltip<\/h3>\n<p>Finally, let\u2019s configure the JS choropleth map&#8217;s tooltip so that it shows information about total cases if you hover over a country&#8217;s territory and total deaths if you hover over a bubble.<\/p>\n<p>The code to achieve this can\u00a0look as follows:<\/p>\n<pre><code class=\"javascript\">\/\/ tooltip formatting\r\nseries.tooltip().format(\"Total Confirmed Cases: {%value}\");\r\nseries_1.tooltip().format(\"Total Deaths: {%size}\");<\/code><\/pre>\n<p>Look at\u00a0the result \u2014 you can also find it on <a href=\"https:\/\/playground.anychart.com\/yxvsY5tD\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a> with the full code:<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-yxvsY5tD\" src=\"https:\/\/playground.anychart.com\/yxvsY5tD\/iframe\" width=\"300\" height=\"150\" frameborder=\"0\" sandbox=\"allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms\" allowfullscreen=\"allowfullscreen\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-yxvsY5tD{width:100%;height:500px;}\");\n})();<\/script><\/p>\n<p>Just in case, here\u2019s the code of the final customized choropleth map coded in JavaScript, which can now be easily embedded into a web, mobile or standalone project:<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n  &lt;title&gt;Choropleth Map&lt;\/title&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/js\/anychart-core.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/js\/anychart-map.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/geodata\/custom\/world\/world.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/proj4js\/2.3.15\/proj4.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.7.1\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;\r\n\r\n  &lt;style&gt;\r\n    html,\r\n    body,\r\n    #container {\r\n      width: 100%;\r\n      height: 100%;\r\n      margin: 0;\r\n      padding: 0;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n  &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n  &lt;script&gt;\r\n\r\n    anychart.onDocumentReady(function () {\r\n\r\n      \/\/ load the data\r\n      anychart.data.loadJsonFile(\"https:\/\/static.anychart.com\/git-storage\/word-press\/data\/choropleth-map-tutorial\/data.json\", function (data) {\r\n\r\n        \/\/ Variables\r\n        \/\/ go into the records section of the data\r\n        var geoData = data.records\r\n\r\n        \/\/ sum of all cases per country\r\n        var sumCases = 0;\r\n\r\n        \/\/ sum of all deaths per country\r\n        var sumDeaths = 0;\r\n\r\n        \/\/ convert cases and deaths to numbers\r\n        var numC;\r\n        var numD;\r\n\r\n        \/\/ create a new array with the resulting data\r\n        var data = [];\r\n\r\n        \/\/ Go through the initial data\r\n        for (var i = 0; i &lt; geoData.length; i++) {\r\n          \/\/ convert strings to numbers and save them to new variables\r\n          numC = parseInt(geoData[i].cases);\r\n          numD = parseInt(geoData[i].deaths);\r\n\r\n          \/\/ check if we are in the same country by comparing the geoId. \r\n          \/\/ if the country is the same add the cases and deaths to the appropriate variables\r\n          if ((geoData[i + 1]) != null &amp;&amp; (geoData[i].geoId == geoData[i + 1].geoId)) {\r\n            sumCases = sumCases + numC;\r\n            sumDeaths = sumDeaths + numD;\r\n          }\r\n          else {\r\n            \/\/ add last day cases and deaths of the same country\r\n            sumCases = sumCases + numC;\r\n            sumDeaths = sumDeaths + numD;\r\n\r\n            \/\/ insert the resulting data in the array using the AnyChart keywords \r\n            data.push({ id: geoData[i].geoId, value: sumCases, size: sumDeaths, title: geoData[i].countriesAndTerritories })\r\n\r\n            \/\/ reset the variables to start over\r\n            sumCases = 0;\r\n            sumDeaths = 0;\r\n\r\n          }\r\n        };\r\n\r\n        \/\/ connect the data with the map\r\n        var chart = anychart.map(data);\r\n        chart.geoData(anychart.maps.world);\r\n\r\n        \/\/ specify the chart type and set the series \r\n        var series = chart.choropleth(data);\r\n\r\n        \/\/ variable to store data that will be used for bubbles\r\n        var bubbleData = [];\r\n\r\n        \/\/ store only the countries that have at least 1 death\r\n        for (var i = 0; i &lt; data.length; i++) {\r\n          if (data[i].size &gt; 0) {\r\n            bubbleData.push(data[i]);\r\n          }\r\n        };\r\n\r\n        \/\/ create a series for bubbles\r\n        var series_1 = chart.bubble(bubbleData);\r\n\r\n        \/\/ set the maximum size of the bubble\r\n        chart.maxBubbleSize(25);\r\n\r\n        \/\/ set the minimum size of the bubble\r\n        chart.minBubbleSize(3);\r\n\r\n        \/\/ set colors and stroke of bubbles\r\n        series_1.normal().fill(\"black\", 0.3);\r\n        series_1.hovered().fill(\"black\", 0.1);\r\n        series_1.selected().fill(\"black\", 0.5);\r\n        series_1.normal().stroke(\"rgb(150,33,31)\");\r\n        series_1.hovered().stroke(\"rgb(150,33,31)\", 2);\r\n        series_1.selected().stroke(\"rgb(150,33,31)\", 4);\r\n\r\n        \/\/ set the chart title\r\n        chart.title(\"COVID-19 Global Cases\");\r\n\r\n        \/\/ color scale ranges\r\n        ocs = anychart.scales.ordinalColor([\r\n          { less: 99 },\r\n          { from: 100, to: 999 },\r\n          { from: 1000, to: 9999 },\r\n          { from: 10000, to: 29999 },\r\n          { from: 30000, to: 39000 },\r\n          { from: 40000, to: 59000 },\r\n          { from: 60000, to: 99999 },\r\n          { greater: 100000 }\r\n        ]);\r\n\r\n        \/\/ set scale colors\r\n        ocs.colors([\"rgb(252,245,245)\", \"rgb(241,219,216)\", \"rgb(229,190,185)\", \"rgb(211,152,145)\", \"rgb(192,117,109)\", \"rgb(178,93,86)\", \"rgb(152,50,48)\", \"rgb(150,33,31)\"]);\r\n\r\n        \/\/ tell the series what to use as a colorRange (colorScale)\r\n        series.colorScale(ocs);\r\n\r\n        \/\/ enable the legend\r\n        chart.legend(true);\r\n\r\n        \/\/ set the source mode of the legend and add styles\r\n        chart.legend()\r\n          .itemsSourceMode(\"categories\")\r\n          .position('right')\r\n          .align('top')\r\n          .itemsLayout('vertical')\r\n          .padding(50, 0, 0, 20)\r\n          .paginator(false);\r\n\r\n        \/\/ tooltip formatting\r\n        series.tooltip().format(\"Total Confirmed Cases: {%value}\");\r\n        series_1.tooltip().format(\"Total Deaths: {%size}\");\r\n\r\n        \/\/ set the container id\r\n        chart.container('container');\r\n\r\n        \/\/ draw the chart\r\n        chart.draw();\r\n      });\r\n\r\n\r\n    });\r\n  &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>In\u00a0this tutorial, I have shown you in detail how to create an interactive JavaScript choropleth map chart. Such data visualizations can be a really helpful tool for\u00a0analyzing statistics at a glance.<\/p>\n<p>Feel free to play with the code of the JS choropleth map samples built along the tutorial. For example, would you like to add <a href=\"https:\/\/docs.anychart.com\/Common_Settings\/UI_Controls\/Zoom_Controls\" target=\"_blank\" rel=\"nofollow\">zoom UI controls<\/a>\u00a0next? You can also visit the <a href=\"https:\/\/www.anychart.com\/products\/anymap\/gallery\/Maps_Choropleth\/\">AnyChart gallery<\/a> to see\u00a0more demos of choropleth, bubble, and other JS maps.<\/p>\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>These days you see choropleth maps in a variety of webpages and utilized for various subjects. Have you wondered how such data visualizations are built? Are you interested in making them by yourself? If so, stay with me through this JS charting tutorial, where I will show you how\u00a0to\u00a0create an interactive JavaScript choropleth map from [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,66,263,23,13,279,4],"tags":[53,235,1740,258,732,104,1925,1769,1936,1824,1934,1935,471,266,54,256,844,32,55,150,144,809,36,907,141,81,57,67,147,58,65,56,68,1937,1938,1728,340,237,1770,459,30,172,1939],"class_list":["post-10302","post","type-post","status-publish","format-standard","hentry","category-anychart-charting-component","category-anymap","category-big-data","category-html5","category-javascript","category-javascript-chart-tutorials","category-tips-and-tricks","tag-anychart","tag-bubble-map","tag-bubble-maps","tag-charts","tag-choropleth-map","tag-choropleth-maps","tag-covid","tag-covid-19","tag-covid-19-cases","tag-covid-19-deaths","tag-covid-19-map","tag-covid-19-statistics","tag-data-analysis","tag-data-analytics","tag-data-visualization","tag-data-visualization-examples","tag-data-visualization-tutorial","tag-html5","tag-html5-charts","tag-html5-maps","tag-infographics","tag-interactive-maps","tag-javascript","tag-javascript-chart-tutorial","tag-javascript-charting","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-map","tag-javascript-maps","tag-js-chart","tag-js-charting","tag-js-charts","tag-js-maps","tag-json","tag-json-data-visualization","tag-map","tag-map-visualizations","tag-maps","tag-ncov-2019","tag-statistics","tag-tips-and-tricks","tag-tutorial","tag-visualizing-json-data","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Choropleth Map: How to Create It Using JavaScript for Data Visualization<\/title>\n<meta name=\"description\" content=\"Need a choropleth map for your web page or app? This tutorial explains how to quickly create such a data visualization using JavaScript, a JS choropleth map\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating Choropleth Map Using JavaScript, on COVID-19 Stats\" \/>\n<meta property=\"og:description\" content=\"Need a choropleth map for your web page or app? This tutorial explains how to quickly create such a data visualization using JavaScript, a JS choropleth map\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"AnyChart News\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/AnyCharts\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-06T06:19:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-13T10:58:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png\" \/>\n<meta name=\"author\" content=\"Anastasia Zoumpliou\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Creating Choropleth Map Using JavaScript, on COVID-19 Stats\" \/>\n<meta name=\"twitter:description\" content=\"Need a choropleth map for your web page or app? This tutorial explains how to quickly create such a data visualization using JavaScript, a JS choropleth map\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png\" \/>\n<meta name=\"twitter:creator\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:site\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anastasia Zoumpliou\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/\"},\"author\":{\"name\":\"Anastasia Zoumpliou\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff\"},\"headline\":\"Creating Choropleth Map Data Visualization Using JavaScript, on COVID-19 Stats\",\"datePublished\":\"2020-05-06T06:19:30+00:00\",\"dateModified\":\"2022-08-13T10:58:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/\"},\"wordCount\":1688,\"commentCount\":2,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png\",\"keywords\":[\"AnyChart\",\"bubble map\",\"bubble maps\",\"charts\",\"choropleth map\",\"choropleth maps\",\"covid\",\"COVID-19\",\"COVID-19 cases\",\"COVID-19 deaths\",\"COVID-19 map\",\"COVID-19 statistics\",\"data analysis\",\"data analytics\",\"Data Visualization\",\"data visualization examples\",\"data visualization tutorial\",\"HTML5\",\"html5 charts\",\"html5 maps\",\"infographics\",\"interactive maps\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"JavaScript charting library\",\"javascript charts\",\"javascript map\",\"javascript maps\",\"js chart\",\"js charting\",\"js charts\",\"js maps\",\"JSON\",\"JSON data visualization\",\"map\",\"map visualizations\",\"maps\",\"nCoV-2019\",\"statistics\",\"Tips and tricks\",\"tutorial\",\"visualizing JSON data\"],\"articleSection\":[\"AnyChart Charting Component\",\"AnyMap\",\"Big Data\",\"HTML5\",\"JavaScript\",\"JavaScript Chart Tutorials\",\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/\",\"name\":\"Choropleth Map: How to Create It Using JavaScript for Data Visualization\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png\",\"datePublished\":\"2020-05-06T06:19:30+00:00\",\"dateModified\":\"2022-08-13T10:58:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff\"},\"description\":\"Need a choropleth map for your web page or app? This tutorial explains how to quickly create such a data visualization using JavaScript, a JS choropleth map\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png\",\"width\":1400,\"height\":884},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Creating Choropleth Map Data Visualization Using JavaScript, on COVID-19 Stats\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\",\"url\":\"https:\/\/www.anychart.com\/blog\/\",\"name\":\"AnyChart News\",\"description\":\"AnyChart JS Charts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.anychart.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff\",\"name\":\"Anastasia Zoumpliou\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/774bd2dbe4c628607dd7ac40f009135e92ba9ab1027bccf9f63351bca2dd919e?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/774bd2dbe4c628607dd7ac40f009135e92ba9ab1027bccf9f63351bca2dd919e?s=96&r=g\",\"caption\":\"Anastasia Zoumpliou\"},\"url\":\"https:\/\/www.anychart.com\/blog\/author\/anastasia-zoumpliou\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Choropleth Map: How to Create It Using JavaScript for Data Visualization","description":"Need a choropleth map for your web page or app? This tutorial explains how to quickly create such a data visualization using JavaScript, a JS choropleth map","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Creating Choropleth Map Using JavaScript, on COVID-19 Stats","og_description":"Need a choropleth map for your web page or app? This tutorial explains how to quickly create such a data visualization using JavaScript, a JS choropleth map","og_url":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2020-05-06T06:19:30+00:00","article_modified_time":"2022-08-13T10:58:50+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png","type":"","width":"","height":""}],"author":"Anastasia Zoumpliou","twitter_card":"summary_large_image","twitter_title":"Creating Choropleth Map Using JavaScript, on COVID-19 Stats","twitter_description":"Need a choropleth map for your web page or app? This tutorial explains how to quickly create such a data visualization using JavaScript, a JS choropleth map","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Anastasia Zoumpliou","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/"},"author":{"name":"Anastasia Zoumpliou","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff"},"headline":"Creating Choropleth Map Data Visualization Using JavaScript, on COVID-19 Stats","datePublished":"2020-05-06T06:19:30+00:00","dateModified":"2022-08-13T10:58:50+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/"},"wordCount":1688,"commentCount":2,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png","keywords":["AnyChart","bubble map","bubble maps","charts","choropleth map","choropleth maps","covid","COVID-19","COVID-19 cases","COVID-19 deaths","COVID-19 map","COVID-19 statistics","data analysis","data analytics","Data Visualization","data visualization examples","data visualization tutorial","HTML5","html5 charts","html5 maps","infographics","interactive maps","JavaScript","javascript chart tutorial","javascript charting","JavaScript charting library","javascript charts","javascript map","javascript maps","js chart","js charting","js charts","js maps","JSON","JSON data visualization","map","map visualizations","maps","nCoV-2019","statistics","Tips and tricks","tutorial","visualizing JSON data"],"articleSection":["AnyChart Charting Component","AnyMap","Big Data","HTML5","JavaScript","JavaScript Chart Tutorials","Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/","url":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/","name":"Choropleth Map: How to Create It Using JavaScript for Data Visualization","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png","datePublished":"2020-05-06T06:19:30+00:00","dateModified":"2022-08-13T10:58:50+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff"},"description":"Need a choropleth map for your web page or app? This tutorial explains how to quickly create such a data visualization using JavaScript, a JS choropleth map","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/05\/js-choropleth-map-html5-tutorial.png","width":1400,"height":884},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2020\/05\/06\/javascript-choropleth-map-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Creating Choropleth Map Data Visualization Using JavaScript, on COVID-19 Stats"}]},{"@type":"WebSite","@id":"https:\/\/www.anychart.com\/blog\/#website","url":"https:\/\/www.anychart.com\/blog\/","name":"AnyChart News","description":"AnyChart JS Charts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.anychart.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/f5cd0be5c1240a1276a6b36bfeca2bff","name":"Anastasia Zoumpliou","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/774bd2dbe4c628607dd7ac40f009135e92ba9ab1027bccf9f63351bca2dd919e?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/774bd2dbe4c628607dd7ac40f009135e92ba9ab1027bccf9f63351bca2dd919e?s=96&r=g","caption":"Anastasia Zoumpliou"},"url":"https:\/\/www.anychart.com\/blog\/author\/anastasia-zoumpliou\/"}]}},"_links":{"self":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/10302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/comments?post=10302"}],"version-history":[{"count":47,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/10302\/revisions"}],"predecessor-version":[{"id":15494,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/10302\/revisions\/15494"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=10302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=10302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=10302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}