{"id":16641,"date":"2023-05-30T07:21:20","date_gmt":"2023-05-30T07:21:20","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=16641"},"modified":"2023-05-30T14:22:13","modified_gmt":"2023-05-30T14:22:13","slug":"heatmap-js","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/","title":{"rendered":"How to Build Heatmap in JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs.png\" alt=\"Heatmap in JavaScript\" width=\"100%\" class=\"alignnone size-full wp-image-16649\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs.png 1400w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs-300x171.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs-768x439.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs-1024x585.png 1024w\" sizes=\"(max-width: 1400px) 100vw, 1400px\" \/><\/a>Data visualization is a powerful tool that helps us make sense of complex data. With it, we can spot patterns and trends that might take much more time to become obvious just by looking at raw numbers. One particularly useful chart type is the <strong>heatmap<\/strong>, and I\u2019m excited to teach you how to create one with JavaScript in this tutorial.<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2 id=\"what-is-a-heatmap\">What is a Heatmap?<\/h2>\n<p>A heatmap is a two-dimensional representation of the magnitude of a phenomenon through colors. It provides a <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/heatmap\/\">quick visual summary<\/a> of high and low values in the data. <\/p>\n<p>For instance, did you know that an average of 108 people died per day in road accidents in the U.S. in 2021? Using a heatmap chart, we can analyze the days and times of fatal accidents. This will be the visualization we will be building during the tutorial.<\/p>\n<p>So, grab your cup of coffee and let&#8217;s dive into this step-by-step guide. By the end, you&#8217;ll have the skills to easily create your own interactive JavaScript heatmaps.<\/p>\n<h1 id=\"the-heatmap-chart-we-ll-build\">The Heatmap Chart We&#8217;ll Build<\/h1>\n<p>Here is how the final JS-based heatmap chart will look:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchart-006.png\" alt=\"Here is how the final JS-based heatmap chart will look\" width=\"100%\" class=\"alignnone size-full wp-image-16648\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchart-006.png 1141w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchart-006-300x170.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchart-006-768x435.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchart-006-1024x581.png 1024w\" sizes=\"(max-width: 1141px) 100vw, 1141px\" \/><\/p>\n<p>Ready to dive in? Let&#8217;s go!<\/p>\n<h1 id=\"how-to-make-a-javascript-heatmap\"><strong>How to Make a JavaScript Heatmap<\/strong><\/h1>\n<p>Great, let&#8217;s start creating a simple yet beautiful heatmap chart using JavaScript. With just four easy-to-follow steps, you&#8217;ll have a stunning interactive heatmap in no time. <\/p>\n<p>Don&#8217;t worry about any complicated coding or overwhelming technicalities. We&#8217;ll keep things straightforward and easy to understand.<\/p>\n<h2 id=\"1-create-an-html-page\">1. Create an HTML Page<\/h2>\n<p>First things first, we need to create a web page that&#8217;ll hold our super-cool heatmap. We start by making a basic HTML page, complete with a <code>div<\/code> element to hold our chart. Let\u2019s also specify the style of the <code>div<\/code> to make it stretch over the whole page. Don&#8217;t worry, it\u2019s easy-peasy:<\/p>\n<pre><code class=\"language-html\">&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;title&gt;Heatmap in JavaScript&lt;\/title&gt;\r\n    &lt;style type=\"text\/css\"&gt;      \r\n      html, body, #container { \r\n        width: 100%; margin: 0; padding: 0; \r\n      } \r\n    &lt;\/style&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2 id=\"2-include-the-required-javascript-files\">2. Include the Required JavaScript Files<\/h2>\n<p>Okay, let&#8217;s be real: building a JS heatmap from scratch would be a real pain in the you-know-what. Instead, we&#8217;re gonna take the easier route and use a JavaScript charting library. <\/p>\n<p>There are a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">ton of various JS charting libraries<\/a> out there. For this project, we&#8217;re gonna go with the <a href=\"https:\/\/www.anychart.com\/\">AnyChart JS library<\/a>, which supports heatmap charts and is free for personal and other non-profit purposes. <\/p>\n<p>To make things work, we need to add a couple of scripts to our web page&#8217;s <code>&lt;head&gt;<\/code> section. Specifically, we need to include the core and heatmap modules. Sounds easy, right?<\/p>\n<pre><code class=\"language-html\">&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;title&gt;Heatmap in JavaScript&lt;\/title&gt;\r\n    &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.1\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n    &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.1\/js\/anychart-heatmap.min.js\"&gt;&lt;\/script&gt; \r\n    &lt;style type=\"text\/css\"&gt;      \r\n      html, body, #container { \r\n        width: 100%; margin: 0; padding: 0; \r\n      } \r\n    &lt;\/style&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;  \r\n    &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n    &lt;script&gt;\r\n      \/\/ All the code for the JS heatmap will come here\r\n    &lt;\/script&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2 id=\"3-add-the-data\">3. Add the Data<\/h2>\n<p>Each chart is complete with the data, right? We\u2019re gonna grab our data from the <a href=\"https:\/\/injuryfacts.nsc.org\/motor-vehicle\/overview\/crashes-by-time-of-day-and-day-of-week\/\" target=\"_blank\" rel=\"nofollow\">NSC website<\/a> and add it to our HTML file in the proper format.<\/p>\n<p>For our heatmap, each data point needs to include an <code>x<\/code> value (day), a <code>y<\/code> value (hour), and a <code>heat<\/code> value (number of accidents). We&#8217;ll wrap this data in a function that we&#8217;ll call when we create the JS chart.<\/p>\n<pre><code class=\"language-javascript\">function getData() {\r\n  return [\r\n    {\r\n      x: \"Monday\",\r\n      y: \"Midnight\u20133:59 a.m.\",\r\n      heat: 705\r\n    },\r\n    {\r\n      x: \"Monday\",\r\n      y: \"4:00\u20137:59 a.m.\",\r\n      heat: 713\r\n    },\r\n    {\r\n      x: \"Monday\",\r\n      y: \"8:00\u201311:59 a.m.\",\r\n      heat: 657\r\n    },\r\n    {\r\n      x: \"Monday\",\r\n      y: \"Noon\u20133:59 p.m.\",\r\n      heat: 957\r\n    },\r\n    {\r\n      x: \"Monday\",\r\n      y: \"4:00\u20137:59 p.m.\",\r\n      heat: 1137\r\n    },\r\n    {\r\n      x: \"Monday\",\r\n      y: \"8:00\u201311:59 p.m.\",\r\n      heat: 956\r\n    },\r\n    {\r\n      x: \"Tuesday\",\r\n      y: \"Midnight\u20133:59 a.m.\",\r\n      heat: 482\r\n    },\r\n    {\r\n      x: \"Tuesday\",\r\n      y: \"4:00\u20137:59 a.m.\",\r\n      heat: 641\r\n    },\r\n    {\r\n      x: \"Tuesday\",\r\n      y: \"8:00\u201311:59 a.m.\",\r\n      heat: 631\r\n    },\r\n    {\r\n      x: \"Tuesday\",\r\n      y: \"Noon\u20133:59 p.m.\",\r\n      heat: 905\r\n    },\r\n    {\r\n      x: \"Tuesday\",\r\n      y: \"4:00\u20137:59 p.m.\",\r\n      heat: 1137\r\n    },\r\n    {\r\n      x: \"Tuesday\",\r\n      y: \"8:00\u201311:59 p.m.\",\r\n      heat: 986\r\n    },\r\n    {\r\n      x: \"Wednesday\",\r\n      y: \"Midnight\u20133:59 a.m.\",\r\n      heat: 465\r\n    },\r\n    {\r\n      x: \"Wednesday\",\r\n      y: \"4:00\u20137:59 a.m.\",\r\n      heat: 616\r\n    },\r\n    {\r\n      x: \"Wednesday\",\r\n      y: \"8:00\u201311:59 a.m.\",\r\n      heat: 627\r\n    },\r\n    {\r\n      x: \"Wednesday\",\r\n      y: \"Noon\u20133:59 p.m.\",\r\n      heat: 914\r\n    },\r\n    {\r\n      x: \"Wednesday\",\r\n      y: \"4:00\u20137:59 p.m.\",\r\n      heat: 1159\r\n    },\r\n    {\r\n      x: \"Wednesday\",\r\n      y: \"8:00\u201311:59 p.m.\",\r\n      heat: 1066\r\n    },\r\n    {\r\n      x: \"Thursday\",\r\n      y: \"Midnight\u20133:59 a.m.\",\r\n      heat: 584\r\n    },\r\n    {\r\n      x: \"Thursday\",\r\n      y: \"4:00\u20137:59 a.m.\",\r\n      heat: 718\r\n    },\r\n    {\r\n      x: \"Thursday\",\r\n      y: \"8:00\u201311:59 a.m.\",\r\n      heat: 660\r\n    },\r\n    {\r\n      x: \"Thursday\",\r\n      y: \"Noon\u20133:59 p.m.\",\r\n      heat: 966\r\n    },\r\n    {\r\n      x: \"Thursday\",\r\n      y: \"4:00\u20137:59 p.m.\",\r\n      heat: 1161\r\n    },\r\n    {\r\n      x: \"Thursday\",\r\n      y: \"8:00\u201311:59 p.m.\",\r\n      heat: 1186\r\n    },\r\n    {\r\n      x: \"Friday\",\r\n      y: \"Midnight\u20133:59 a.m.\",\r\n      heat: 715\r\n    },\r\n    {\r\n      x: \"Friday\",\r\n      y: \"4:00\u20137:59 a.m.\",\r\n      heat: 747\r\n    },\r\n    {\r\n      x: \"Friday\",\r\n      y: \"8:00\u201311:59 a.m.\",\r\n      heat: 738\r\n    },\r\n    {\r\n      x: \"Friday\",\r\n      y: \"Noon\u20133:59 p.m.\",\r\n      heat: 1056\r\n    },\r\n    {\r\n      x: \"Friday\",\r\n      y: \"4:00\u20137:59 p.m.\",\r\n      heat: 1426\r\n    },\r\n    {\r\n      x: \"Friday\",\r\n      y: \"8:00\u201311:59 p.m.\",\r\n      heat: 1631\r\n    },\r\n    {\r\n      x: \"Saturday\",\r\n      y: \"Midnight\u20133:59 a.m.\",\r\n      heat: 1383\r\n    },\r\n    {\r\n      x: \"Saturday\",\r\n      y: \"4:00\u20137:59 a.m.\",\r\n      heat: 641\r\n    },\r\n    {\r\n      x: \"Saturday\",\r\n      y: \"8:00\u201311:59 a.m.\",\r\n      heat: 635\r\n    },\r\n    {\r\n      x: \"Saturday\",\r\n      y: \"Noon\u20133:59 p.m.\",\r\n      heat: 1034\r\n    },\r\n    {\r\n      x: \"Saturday\",\r\n      y: \"4:00\u20137:59 p.m.\",\r\n      heat: 1400\r\n    },\r\n    {\r\n      x: \"Saturday\",\r\n      y: \"8:00\u201311:59 p.m.\",\r\n      heat: 1593\r\n    },\r\n    {\r\n      x: \"Sunday\",\r\n      y: \"Midnight\u20133:59 a.m.\",\r\n      heat: 1486\r\n    },\r\n    {\r\n      x: \"Sunday\",\r\n      y: \"4:00\u20137:59 a.m.\",\r\n      heat: 695\r\n    },\r\n    {\r\n      x: \"Sunday\",\r\n      y: \"8:00\u201311:59 a.m.\",\r\n      heat: 564\r\n    },\r\n    {\r\n      x: \"Sunday\",\r\n      y: \"Noon\u20133:59 p.m.\",\r\n      heat: 932\r\n    },\r\n    {\r\n      x: \"Sunday\",\r\n      y: \"4:00\u20137:59 p.m.\",\r\n      heat: 1292\r\n    },\r\n    {\r\n      x: \"Sunday\",\r\n      y: \"8:00\u201311:59 p.m.\",\r\n      heat: 1211\r\n    }\r\n  ];\r\n}<\/code><\/pre>\n<h2 id=\"4-write-the-necessary-js-code-for-the-chart\">4. Write the Necessary JS Code for the Chart<\/h2>\n<p>Here&#8217;s the fun part: it&#8217;s time to write the JavaScript code that&#8217;ll make our heatmap chart look amazing.<\/p>\n<p>We&#8217;ll enclose everything in a function to ensure the code only executes when the page is ready. We&#8217;ll create the graph using the <code>heatMap()<\/code> function and add the data we created in the previous step.<\/p>\n<pre><code class=\"language-js\">let chart = anychart.heatMap(getData());<\/code><\/pre>\n<p>Then, we&#8217;ll give the chart a descriptive title:<\/p>\n<pre><code class=\"language-js\">chart.title(\"Fatal Car Crashes in U.S. in 2021 by Time of Day and Day of Week\u201d);<\/code><\/pre>\n<p>Finally, we&#8217;ll set the container reference and draw the chart. Voil\u00e0!<\/p>\n<pre><code class=\"language-js\">\u0441hart.container('container\u2019);\r\nchart.draw();<\/code><\/pre>\n<p>And there you have it. With just a little bit of HTML and JavaScript, you can create a totally rad interactive heatmap. You can see the entire code of this JS-based heatmap below and check it out live <a href=\"https:\/\/playground.anychart.com\/DEyz9Bjb\" target=\"_blank\" rel=\"nofollow\">here<\/a>. After that, we&#8217;ll learn how to customize our heatmap in all kinds of fun ways.<\/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-DEyz9Bjb\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/DEyz9Bjb\/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-DEyz9Bjb{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<pre><code class=\"language-html\">&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;title&gt;Heatmap in JavaScript&lt;\/title&gt;\r\n    &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.1\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n    &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.1\/js\/anychart-heatmap.min.js\"&gt;&lt;\/script&gt; \r\n    &lt;style type=\"text\/css\"&gt;      \r\n      html, body, #container { \r\n        width: 100%; margin: 0; padding: 0; \r\n      } \r\n    &lt;\/style&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;  \r\n    &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n    &lt;script&gt;\r\n      anychart.onDocumentReady(function () {\r\n        \/\/ create a heatmap\r\n        let chart = anychart.heatMap(getData());\r\n        \/\/ name the heatmap\r\n        chart.title(\"Fatal Car Crashes in U.S. in 2021 by Time of Day and Day of Week\");\r\n        \/\/ set the container for the heatmap\r\n        chart.container(\"container\");\r\n        \/\/ draw the heatmap\r\n        chart.draw();\r\n      });\r\n      \/\/ add the data\r\n      function getData() {\r\n        return [\r\n          {\r\n            x: \"Monday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 705\r\n          },\r\n          {\r\n            x: \"Monday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 713\r\n          },\r\n          {\r\n            x: \"Monday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 657\r\n          },\r\n          {\r\n            x: \"Monday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 957\r\n          },\r\n          {\r\n            x: \"Monday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1137\r\n          },\r\n          {\r\n            x: \"Monday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 956\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 482\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 641\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 631\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 905\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1137\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 986\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 465\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 616\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 627\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 914\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1159\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 1066\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 584\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 718\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 660\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 966\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1161\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 1186\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 715\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 747\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 738\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 1056\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1426\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 1631\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 1383\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 641\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 635\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 1034\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1400\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 1593\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 1486\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 695\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 564\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 932\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1292\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 1211\r\n          }\r\n        ];\r\n      }\r\n    &lt;\/script&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<p>This heatmap is both visually appealing and informative. Upon examining the chart, it becomes clear that there are certain times when the number of accidents is significantly higher. It is unsurprising to see that these peak times are during weekends and the darker hours of the day.<\/p>\n<p>But there&#8217;s a lot more we can do with our heatmap&#8230;<\/p>\n<h1 id=\"how-to-customize-a-js-heatmap\"><strong>How to Customize a JS Heatmap<\/strong><\/h1>\n<p>As we saw, having the basic chart ready was really simple and fast. But there is so much more we can do to enhance the heatmap. It&#8217;s not so difficult, either. <\/p>\n<h2 id=\"how-to-change-the-color-palette\">How to Change the Color Palette<\/h2>\n<p>We can use a diverging color palette to make our JavaScript heatmap more effective in highlighting the data. This type of color scheme helps to emphasize the difference between high and low values, with less being good and more being alarming. <\/p>\n<p>We can define four colors and value ranges using an ordinal color scale and then set the chart colors to use that color scale. This way, we can create a heatmap that quickly draws the viewer&#8217;s attention to the most significant data points.<\/p>\n<p>Here&#8217;s the code to do that:<\/p>\n<pre><code>let colorScale = anychart.scales.ordinalColor();\r\ncolorScale.ranges([\r\n  { less: 500, color: \"#B0D8A4\" },\r\n  { from: 500, to: 900, color: \"#FEE191\" },\r\n  { from: 900, to: 1300, color: \"#FD8060\" },\r\n  { greater: 1300, color: \"#CC333F\" }\r\n]);\r\nchart.colorScale(colorScale);<\/code><\/pre>\n<p>And here&#8217;s the result:<\/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-1u9b5DhE\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/1u9b5DhE\/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-1u9b5DhE{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h2 id=\"how-to-modify-the-hover-styling\">How to Modify the Hover Styling<\/h2>\n<p>When we change the color palette of our heatmap, we also need to modify the hover colors to match the base colors. This is simple to achieve with the <code>color.darken<\/code> function. <\/p>\n<p>We can set the chart settings and hover chart settings to ensure that the hover colors match the base colors. This allows us to create a visually consistent and easy-to-read heatmap, making it more effective in communicating the underlying data.<\/p>\n<pre><code>chart\r\n  .hovered()\r\n  .fill(function () {\r\n    return anychart.color.darken(this.sourceColor, 0.25);\r\n  });<\/code><\/pre>\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-y4v6NtQU\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/y4v6NtQU\/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-y4v6NtQU{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h2 id=\"how-to-change-the-labels\">How to Change the Labels<\/h2>\n<p>By default, the labels on our heatmap show the actual numbers. But we can customize the labels to provide greater flexibility and make the chart easier to read. <\/p>\n<p>We can enable HTML for the labels to allow for greater formatting options. Then, we can configure the labels to display as &#8216;low&#8217; to &#8216;extreme&#8217; based on the value of the tile. We can also make the &#8216;high&#8217; and &#8216;extreme&#8217; values appear in bold to make them stand out.<\/p>\n<pre><code class=\"language-javascript\">\/\/ enable html for the labels\r\nchart.labels().useHtml(true);\r\n\r\n\/\/ configure the labels\r\nchart.labels().format(function () {\r\n  var heat = this.heat;\r\n  if (heat &lt; 500) return \"Low\";\r\n  if (heat &lt; 1000) return \"Medium\";\r\n  if (heat &lt; 1500) return \"&lt;span style='font-weight:bold'&gt;High&lt;\/span&gt;\";\r\n  if (heat &gt;= 1500) return \"&lt;span style='font-weight:bold'&gt;Extreme&lt;\/span&gt;\";\r\n});<\/code><\/pre>\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-y4v6NtQU\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/bQcnIsUf\/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-bQcnIsUf{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>In the final version, I decided to ultimately remove the labels since the colors are quite indicative of the values.<\/p>\n<pre><code>chart.labels(false);<\/code><\/pre>\n<h2 id=\"how-to-format-the-title-and-tooltip\">How to Format the Title and Tooltip<\/h2>\n<p>Now it&#8217;s time to make our JS heatmap visualization even more exciting with some formatting tweaks. <\/p>\n<p>First, we&#8217;ll enable HTML for the tooltip, so we can customize it with some eye-catching formatting. We&#8217;ll display the number of accidents in the heading and the day as well as the timing in the body of the tooltip. This will add more context and help the user to better understand the data.<\/p>\n<pre><code class=\"language-javascript\">chart.tooltip().title().useHtml(true);\r\nchart\r\n  .tooltip()\r\n  .useHtml(true)\r\n  .titleFormat(function () {\r\n    return \"Accidents - \" + this.heat;\r\n  })\r\n  .format(function () {\r\n    return (\r\n      '&lt;span style=\"color: #CECECE\"&gt;Day: &lt;\/span&gt;' +\r\n      this.x +\r\n      \"&lt;br\/&gt;\" +\r\n      '&lt;span style=\"color: #CECECE\"&gt;Time: &lt;\/span&gt;' +\r\n      this.y\r\n    );\r\n  });<\/code><\/pre>\n<p>Let\u2019s also add a bit of padding under the main title to make it more spaced out and visually appealing:<\/p>\n<pre><code class=\"language-javascript\">chart\r\n  .title()\r\n  .enabled(true)\r\n  .text(\"Fatal Car Crashes in U.S. in 2021 by Time of Day and Day of Week\")\r\n  .padding([0, 0, 20, 0]);\t<\/code><\/pre>\n<p>Here&#8217;s what those modifications look like:<\/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-5xnDd2wn\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/5xnDd2wn\/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-5xnDd2wn{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h2 id=\"how-to-modify-the-axes\">How to Modify the Axes<\/h2>\n<p>For better readability, we can add padding between the axes labels and the chart tiles and remove the axes lines since the tiles form a boundary by themselves.<\/p>\n<pre><code class=\"language-javascript\">chart.xAxis().stroke(null);\r\nchart.yAxis().stroke(null);\r\nchart.yAxis().labels().padding([0, 10, 0, 0]);\r\nchart.xAxis().labels().padding([0, 0, 10, 0]);<\/code><\/pre>\n<p>And there you have it! With just a few aesthetic changes, we&#8217;ve transformed a simple heatmap into a stunning visualization that really drives home a powerful message. You can check it out below with the full source code, and you can take a closer look at the interactive version of the heatmap and play with the code live <a href=\"https:\/\/playground.anychart.com\/UDF2ym4E\" target=\"_blank\" rel=\"nofollow\">here<\/a>.<\/p>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-UDF2ym4E\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/UDF2ym4E\/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-UDF2ym4E{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<pre><code class=\"language-html\">&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;title&gt;Heatmap in JavaScript&lt;\/title&gt;\r\n    &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.1\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n    &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.1\/js\/anychart-heatmap.min.js\"&gt;&lt;\/script&gt; \r\n    &lt;style type=\"text\/css\"&gt;      \r\n      html, body, #container { \r\n        width: 100%; margin: 0; padding: 0; \r\n      } \r\n    &lt;\/style&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;  \r\n    &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n    &lt;script&gt;\r\n      anychart.onDocumentReady(function () {\r\n        \/\/ create a heatmap\r\n        var chart = anychart.heatMap(getData());\r\n        \/\/ set a custom color scale\r\n        var colorScale = anychart.scales.ordinalColor();\r\n        colorScale.ranges([\r\n          { less: 500, color: \"#B0D8A4\" },\r\n          { from: 500, to: 900, color: \"#FEE191\" },\r\n          { from: 900, to: 1300, color: \"#FD8060\" },\r\n          { greater: 1300, color: \"#CC333F\" }\r\n        ]);\r\n        chart.colorScale(colorScale);\r\n        \/\/ style the coloring in the hovered state\r\n        chart\r\n          .hovered()\r\n          .fill(function () {\r\n            return anychart.color.darken(this.sourceColor, 0.25);\r\n          });\r\n        \/\/ hide the labels\r\n        chart.labels(false);\r\n        \/\/ customize the axes\r\n        chart.xAxis().stroke(null);\r\n        chart.yAxis().stroke(null);\r\n        chart.yAxis().labels().padding([0, 10, 0, 0]);\r\n        chart.xAxis().labels().padding([0, 0, 10, 0]);\r\n        \/\/ set the tooltip\r\n        chart.tooltip().title().useHtml(true);\r\n        chart\r\n          .tooltip()\r\n          .useHtml(true)\r\n          .titleFormat(function () {\r\n            return \"Accidents - \" + this.heat;\r\n          })\r\n          .format(function () {\r\n            return (\r\n              '&lt;span style=\"color: #CECECE\"&gt;Day: &lt;\/span&gt;' +\r\n              this.x +\r\n              \"&lt;br\/&gt;\" +\r\n              '&lt;span style=\"color: #CECECE\"&gt;Time: &lt;\/span&gt;' +\r\n              this.y\r\n            );\r\n          });\r\n        \/\/ name the heatmap\r\n        chart\r\n          .title()\r\n          .enabled(true)\r\n          .text(\"Fatal Car Crashes in U.S. in 2021 by Time of Day and Day of Week\")\r\n          .padding([0, 0, 20, 0]);\r\n        \/\/ set the container for the heatmap\r\n        chart.container(\"container\");\r\n        \/\/ draw the heatmap\r\n        chart.draw();\r\n      });\r\n      \/\/ add the data\r\n      function getData() {\r\n        return [\r\n          {\r\n            x: \"Monday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 705\r\n          },\r\n          {\r\n            x: \"Monday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 713\r\n          },\r\n          {\r\n            x: \"Monday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 657\r\n          },\r\n          {\r\n            x: \"Monday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 957\r\n          },\r\n          {\r\n            x: \"Monday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1137\r\n          },\r\n          {\r\n            x: \"Monday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 956\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 482\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 641\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 631\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 905\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1137\r\n          },\r\n          {\r\n            x: \"Tuesday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 986\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 465\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 616\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 627\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 914\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1159\r\n          },\r\n          {\r\n            x: \"Wednesday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 1066\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 584\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 718\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 660\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 966\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1161\r\n          },\r\n          {\r\n            x: \"Thursday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 1186\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 715\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 747\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 738\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 1056\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1426\r\n          },\r\n          {\r\n            x: \"Friday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 1631\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 1383\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 641\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 635\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 1034\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1400\r\n          },\r\n          {\r\n            x: \"Saturday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 1593\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"Midnight\u20133:59 a.m.\",\r\n            heat: 1486\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"4:00\u20137:59 a.m.\",\r\n            heat: 695\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"8:00\u201311:59 a.m.\",\r\n            heat: 564\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"Noon\u20133:59 p.m.\",\r\n            heat: 932\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"4:00\u20137:59 p.m.\",\r\n            heat: 1292\r\n          },\r\n          {\r\n            x: \"Sunday\",\r\n            y: \"8:00\u201311:59 p.m.\",\r\n            heat: 1211\r\n          }\r\n        ];\r\n      }\r\n    &lt;\/script&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h1 id=\"conclusion\">Conclusion<\/h1>\n<p>In conclusion, data visualization is an incredibly powerful tool that can help us uncover important insights from our data. And with JavaScript, creating beautiful and impactful charts, such as a heatmap, can be a breeze. <\/p>\n<p>So don&#8217;t be afraid to experiment with different chart types, styles, and libraries to create your own hard-hitting visualizations. And above all, remember to stay safe out there on the roads!<\/p>\n<hr \/>\n<p><strong><em>Published with the permission of Shachee Swadia. Originally appeared on <a href=\"https:\/\/www.freecodecamp.org\/news\/interactive-heatmap-in-javascript\/\" target=\"_blank\" rel=\"nofollow\">freeCodeCamp<\/a> with the title &#8220;How to Create an Interactive Heatmap Using JavaScript&#8221; on May 16, 2023.<\/p>\n<p>You may also like to see the <a href=\"https:\/\/www.anychart.com\/blog\/2020\/02\/26\/heat-map-chart-create-javascript\/\">JavaScript Heat Map Chart Tutorial<\/a> produced by Anastasia Zoumpliou and originally published on our blog earlier.<\/p>\n<p>Check out more <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a> on our blog.<\/p>\n<p>Have an idea for some awesome guest post? <a href=\"https:\/\/www.anychart.com\/support\/\">Drop us a line!<\/a><\/strong><\/p>\n<hr \/>\n<p><!-- SyntaxHighlighter --><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/default.min.css\"><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/atom-one-light.min.css\"><script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/highlight.min.js\"><\/script><script>hljs.initHighlightingOnLoad();<\/script><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Data visualization is a powerful tool that helps us make sense of complex data. With it, we can spot patterns and trends that might take much more time to become obvious just by looking at raw numbers. One particularly useful chart type is the heatmap, and I\u2019m excited to teach you how to create one [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,263,23,13,279,4],"tags":[843,53,3173,260,845,3513,2000,847,561,3552,413,1758,3149,284,127,258,471,266,620,1292,880,806,3352,509,2220,2838,54,1389,1760,2757,256,1111,844,165,313,1370,774,3369,805,1762,217,215,216,1754,2013,2014,32,55,3555,144,167,146,433,152,2949,151,36,907,141,249,81,57,1238,142,96,1755,99,58,65,56,101,3526,3554,3553,2137,459,30,172,309,954,2816,1763,804,3407],"class_list":["post-16641","post","type-post","status-publish","format-standard","hentry","category-anychart-charting-component","category-big-data","category-html5","category-javascript","category-javascript-chart-tutorials","category-tips-and-tricks","tag-advanced-data-visualization","tag-anychart","tag-app-development","tag-best-data-visualization-examples","tag-best-data-visualization-software","tag-best-data-visualization-solution","tag-best-data-visualization-tool","tag-best-data-visualization-tools","tag-best-data-visualizations","tag-car-accidents","tag-causes-of-death","tag-chart-design","tag-chart-development","tag-chart-examples","tag-chart-types","tag-charts","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-chart","tag-data-charting","tag-data-charts","tag-data-graphic","tag-data-graphics","tag-data-visual","tag-data-visualisation","tag-data-visualization","tag-data-visualization-best-pracices","tag-data-visualization-design","tag-data-visualization-development","tag-data-visualization-examples","tag-data-visualization-practice","tag-data-visualization-tutorial","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-dataviz-examples","tag-developers","tag-front-end-development","tag-guest-post","tag-heat-map","tag-heat-map-chart","tag-heatmap","tag-heatmap-chart","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-html5-heatmap","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-heat-map","tag-javascript-library","tag-js-chart","tag-js-charting","tag-js-charts","tag-js-graphics","tag-js-library","tag-nsc","tag-road-fatalities","tag-roads","tag-statistics","tag-tips-and-tricks","tag-tutorial","tag-united-states","tag-visual-data-analytics","tag-web-design","tag-web-developers","tag-web-development","tag-website-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>Heatmap Guide: How to Build Heatmaps in JavaScript<\/title>\n<meta name=\"description\" content=\"Master JS heatmaps in this tutorial! Learn as we visualize data on fatal road accidents in the U.S. step-by-step &amp; spot the most dangerous time in heatmap.\" \/>\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\/2023\/05\/30\/heatmap-js\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Build a Heatmap in JavaScript\" \/>\n<meta property=\"og:description\" content=\"Master JavaScript heatmaps! Learn as we visualize data on fatal road accidents in the U.S. step-by-step &amp; spot the most dangerous time.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-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=\"2023-05-30T07:21:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-30T14:22:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs-soc.png\" \/>\n<meta name=\"author\" content=\"Shachee Swadia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"How to Build a Heatmap in JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"Master JavaScript heatmaps! Learn as we visualize data on fatal road accidents in the U.S. step-by-step &amp; spot the most dangerous time.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs-soc.png\" \/>\n<meta name=\"twitter:creator\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:site\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shachee Swadia\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"How to Build Heatmap in JavaScript\",\"datePublished\":\"2023-05-30T07:21:20+00:00\",\"dateModified\":\"2023-05-30T14:22:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/\"},\"wordCount\":1341,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs.png\",\"keywords\":[\"advanced data visualization\",\"AnyChart\",\"app development\",\"best data visualization examples\",\"best data visualization software\",\"best data visualization solution\",\"best data visualization tool\",\"best data visualization tools\",\"best data visualizations\",\"car accidents\",\"causes of death\",\"chart design\",\"chart development\",\"chart examples\",\"chart types\",\"charts\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data chart\",\"data charting\",\"data charts\",\"data graphic\",\"data graphics\",\"data visual\",\"data visualisation\",\"Data Visualization\",\"data visualization best practices\",\"data visualization design\",\"data visualization development\",\"data visualization examples\",\"data visualization practice\",\"data visualization tutorial\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"dataviz examples\",\"developers\",\"front-end development\",\"guest post\",\"heat map\",\"heat map chart\",\"heatmap\",\"heatmap chart\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"html5 heatmap\",\"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 heat map\",\"JavaScript library\",\"js chart\",\"js charting\",\"js charts\",\"JS graphics\",\"js library\",\"NSC\",\"road fatalities\",\"roads\",\"statistics\",\"Tips and tricks\",\"tutorial\",\"united states\",\"visual data analytics\",\"web design\",\"web developers\",\"web development\",\"website development\"],\"articleSection\":[\"AnyChart Charting Component\",\"Big Data\",\"HTML5\",\"JavaScript\",\"JavaScript Chart Tutorials\",\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/\",\"name\":\"Heatmap Guide: How to Build Heatmaps in JavaScript\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs.png\",\"datePublished\":\"2023-05-30T07:21:20+00:00\",\"dateModified\":\"2023-05-30T14:22:13+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"Master JS heatmaps in this tutorial! Learn as we visualize data on fatal road accidents in the U.S. step-by-step & spot the most dangerous time in heatmap.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs.png\",\"width\":1400,\"height\":800},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Build Heatmap in JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\",\"url\":\"https:\/\/www.anychart.com\/blog\/\",\"name\":\"AnyChart News\",\"description\":\"AnyChart JS Charts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.anychart.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\",\"name\":\"Shachee Swadia\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g\",\"caption\":\"Shachee Swadia\"},\"url\":\"https:\/\/www.anychart.com\/blog\/author\/shachee-swadia\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Heatmap Guide: How to Build Heatmaps in JavaScript","description":"Master JS heatmaps in this tutorial! Learn as we visualize data on fatal road accidents in the U.S. step-by-step & spot the most dangerous time in heatmap.","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\/2023\/05\/30\/heatmap-js\/","og_locale":"en_US","og_type":"article","og_title":"How to Build a Heatmap in JavaScript","og_description":"Master JavaScript heatmaps! Learn as we visualize data on fatal road accidents in the U.S. step-by-step & spot the most dangerous time.","og_url":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2023-05-30T07:21:20+00:00","article_modified_time":"2023-05-30T14:22:13+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs-soc.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"How to Build a Heatmap in JavaScript","twitter_description":"Master JavaScript heatmaps! Learn as we visualize data on fatal road accidents in the U.S. step-by-step & spot the most dangerous time.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs-soc.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"How to Build Heatmap in JavaScript","datePublished":"2023-05-30T07:21:20+00:00","dateModified":"2023-05-30T14:22:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/"},"wordCount":1341,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs.png","keywords":["advanced data visualization","AnyChart","app development","best data visualization examples","best data visualization software","best data visualization solution","best data visualization tool","best data visualization tools","best data visualizations","car accidents","causes of death","chart design","chart development","chart examples","chart types","charts","data analysis","data analytics","data analytics examples","data chart","data charting","data charts","data graphic","data graphics","data visual","data visualisation","Data Visualization","data visualization best practices","data visualization design","data visualization development","data visualization examples","data visualization practice","data visualization tutorial","data visualizations","data visuals","data viz examples","dataviz examples","developers","front-end development","guest post","heat map","heat map chart","heatmap","heatmap chart","HTML","HTML charts","HTML5","html5 charts","html5 heatmap","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 heat map","JavaScript library","js chart","js charting","js charts","JS graphics","js library","NSC","road fatalities","roads","statistics","Tips and tricks","tutorial","united states","visual data analytics","web design","web developers","web development","website development"],"articleSection":["AnyChart Charting Component","Big Data","HTML5","JavaScript","JavaScript Chart Tutorials","Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/","url":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/","name":"Heatmap Guide: How to Build Heatmaps in JavaScript","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs.png","datePublished":"2023-05-30T07:21:20+00:00","dateModified":"2023-05-30T14:22:13+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"Master JS heatmaps in this tutorial! Learn as we visualize data on fatal road accidents in the U.S. step-by-step & spot the most dangerous time in heatmap.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2023\/05\/heatmapchartjs.png","width":1400,"height":800},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2023\/05\/30\/heatmap-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Build Heatmap in JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.anychart.com\/blog\/#website","url":"https:\/\/www.anychart.com\/blog\/","name":"AnyChart News","description":"AnyChart JS Charts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.anychart.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51","name":"Shachee Swadia","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g","caption":"Shachee Swadia"},"url":"https:\/\/www.anychart.com\/blog\/author\/shachee-swadia\/"}]}},"_links":{"self":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/16641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/comments?post=16641"}],"version-history":[{"count":22,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/16641\/revisions"}],"predecessor-version":[{"id":16669,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/16641\/revisions\/16669"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=16641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=16641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=16641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}