{"id":14449,"date":"2022-02-11T12:24:59","date_gmt":"2022-02-11T12:24:59","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=14449"},"modified":"2022-08-16T06:02:31","modified_gmt":"2022-08-16T06:02:31","slug":"calendar-chart-js","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/","title":{"rendered":"How to Create Calendar Chart in JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js.png\" alt=\"Creating a Calendar Chart in JavaScript for a Website, Page or App\" width=\"100%\" class=\"alignnone size-full wp-image-15557\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js.png 1400w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js-300x171.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js-768x438.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js-1024x584.png 1024w\" sizes=\"(max-width: 1400px) 100vw, 1400px\" \/><\/a>A calendar chart is an effective way to represent activity over time graphically. It can nicely display how a quantity varies with the days, weeks, months, and years. If you want to learn to build stylish interactive calendar charts easily using JavaScript, welcome to my step-by-step tutorial!<\/p>\n<p>To make this guide not only educating but also entertaining, I decided to reproduce <a href=\"https:\/\/docs.github.com\/en\/account-and-profile\/setting-up-and-managing-your-github-profile\/managing-contribution-graphs-on-your-profile\/viewing-contributions-on-your-profile#contributions-calendar\" target=\"_blank\" rel=\"nofollow\">GitHub\u2019s calendar graph<\/a> and visualize the repository contribution activity of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mike_Bostock\" target=\"_blank\" rel=\"nofollow\">Mike Bostock<\/a>, a prominent computer scientist known globally as one of the creators of the open-source JavaScript charting library <a href=\"https:\/\/d3js.org\/\" target=\"_blank\" rel=\"nofollow\">D3.js<\/a> and of the interactive data visualization development platform <a href=\"https:\/\/observablehq.com\/\" target=\"_blank\" rel=\"nofollow\">Observable<\/a>. So, we\u2019ll also get a telling picture of how he performed in that regard!<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>Calendar Chart That Will Be Created<\/h2>\n<p>Before anything else, let me get you all pumped up by demonstrating the beautiful JavaScript-based calendar chart of Mike Bostock\u2019s contributions that will be created along this tutorial. Read on to see how it\u2019s built!<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/final-javascript-calendar-chart.png\" alt=\"Interactive JavaScript calendar chart\" width=\"100%\" class=\"alignnone size-full wp-image-14580\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/final-javascript-calendar-chart.png 1400w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/final-javascript-calendar-chart-300x264.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/final-javascript-calendar-chart-768x676.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/final-javascript-calendar-chart-1024x902.png 1024w\" sizes=\"(max-width: 1400px) 100vw, 1400px\" \/><\/p>\n<h2>Basic Interactive JS Calendar Chart<\/h2>\n<p>An interactive JavaScript calendar chart can look a bit complex. But just follow these basic four steps, and you\u2019ll be able to build one quite easily.<\/p>\n<ol>\n<li>Create an HTML page.<\/li>\n<li>Add the required JS files.<\/li>\n<li>Include the data.<\/li>\n<li>Add some JavaScript charting code.<\/li>\n<\/ol>\n<h3>1. Create an HTML page<\/h3>\n<p>Let\u2019s start with the very basics and create an HTML page to render our JS calendar chart.<\/p>\n<p>On this page, add a <code>div<\/code> element with a unique id attribute so that it can be easily referred to in the code later.<\/p>\n<p>For the full-page rendering of the chart, set the width of the <code>div<\/code> as 100%. You may change this to your liking, of course.<\/p>\n<pre><code>&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Calendar Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0  html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0  width: 100%; margin: 0; padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>2. Include the required JavaScript files<\/h3>\n<p>The quickest and most convenient way to create a calendar graph for the web is using a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">JavaScript charting library<\/a> that supports this type of data visualization out of the box.<\/p>\n<p>In this tutorial, we will use <a href=\"https:\/\/www.anychart.com\">AnyChart<\/a> as an example, and the visualization will be built following its <a href=\"https:\/\/docs.anychart.com\/Basic_Charts\/Calendar_Chart\" target=\"_blank\" rel=\"nofollow\">calendar chart documentation<\/a>. This library is free for non-commercial use and has many examples for the various chart types and options. So if you are a beginner, it still looks good for you to start.<\/p>\n<p>Include the required JS files in\u00a0the <code>&lt;head&gt;<\/code> section of the HTML page. Let\u2019s take them from the <a href=\"https:\/\/cdn.anychart.com\" target=\"_blank\" rel=\"nofollow\">CDN<\/a> this time, but you can also download them if you want.<\/p>\n<p>AnyChart has an inherent modular system. We need two charting modules to create a calendar chart: <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#core\" target=\"_blank\" rel=\"nofollow\">core<\/a> and <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#calendar\" target=\"_blank\" rel=\"nofollow\">calendar<\/a>.<\/p>\n<pre><code>&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Calendar Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-calendar.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0  html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0    width: 100%; margin: 0; padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;  \r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ The JS calendar chart code goes here.\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>3. Procure and add the data<\/h3>\n<p>Now, let\u2019s see how to set the data for our calendar chart.<\/p>\n<p>It is easy to retrieve data on the contributions of any GitHub user \u2014 we are looking at <a href=\"https:\/\/github.com\/mbostock\" target=\"_blank\" rel=\"nofollow\">Mike Bostock<\/a> in our case \u2014 via the <a href=\"https:\/\/github.com\/mbostock\" target=\"_blank\" rel=\"nofollow\">GitHub GraphQL API<\/a>.<\/p>\n<p>I have already downloaded it and put it in the appropriate form in a JSON data file <a href=\"https:\/\/gist.githubusercontent.com\/shacheeswadia\/56f3867eb6f8fcc4532e7ac458c8d9f7\/raw\/702f30b457cc1b573093c6977a69958fb741ede6\/calendarData.json\" target=\"_blank\" rel=\"nofollow\">here<\/a>.<\/p>\n<p>To load this file in a straightforward manner, we can use the <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#data_adapter\" target=\"_blank\" rel=\"nofollow\">Data Adapter<\/a>. Therefore, it needs to be referenced in the\u00a0<code>&lt;head&gt;<\/code> section of our HTML page together with the other scripts we will use to create the calendar chart.<\/p>\n<pre><code>&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\n<p>We have all the preparation done now, so let\u2019s get on to the JS coding part. You will not believe how just a few lines will create a functional interactive calendar chart very quickly!<\/p>\n<h3>4. Add the JS charting code<\/h3>\n<p>To ensure that the charting code is executed only when the web page is ready, we must enclose it in the <code>anychart.onDocumentLoad()<\/code> function.<\/p>\n<p>Inside, first, load the JSON data file using the <code>data.loadJsonFile<\/code> function.<\/p>\n<p>Then, create a function with the <code>data<\/code> parameter, define a dataset variable to store the data, map the data, and pass the mapped data to the <code>calendar()<\/code> function.<\/p>\n<pre><code class=\"javascript\">anychart.onDocumentReady(function() {\r\n\r\n\u00a0 \/\/ load the json file\r\n  anychart.data.loadJsonFile(\r\n    'https:\/\/gist.githubusercontent.com\/shacheeswadia\/56f3867eb6f8fcc4532e7ac458c8d9f7\/raw\/702f30b457cc1b573093c6977a69958fb741ede6\/calendarData.json',\r\n\r\n\u00a0 \u00a0 \/\/ create a function with the data parameter\r\n    function(data) {\r\n\r\n      \/\/ define a dataset variable to store the data\r\n      var dataset = anychart.data.set(data);\r\n      \/\/ map the data\r\n      var mapping = dataset.mapAs({\r\n        x: 'date',\r\n        value: 'level'\r\n      });\r\n\r\n      \/\/ pass the mapped data to the calendar function\r\n      var chart = anychart.calendar(mapping);\r\n\r\n    }\r\n\r\n  );\r\n\r\n});<\/code><\/pre>\n<p>Let\u2019s set the height of our calendar chart dynamically based on its actual value, which will enable scrolling in case the chart\u2019s height is greater than the page\u2019s.<\/p>\n<pre><code class=\"javascript\">chart.listen('chartDraw', function() {       \r\n  document.getElementById('container').style.height = chart.getActualHeight() + 'px';\r\n});<\/code><\/pre>\n<p>Lastly, we add a title to make it clear for everyone what is visualized, set the container reference, and draw the resulting chart.<\/p>\n<pre><code class=\"javascript\">chart.title(\"GitHub Contributions of Mike Bostock in 2017\u20132021\");\r\nchart.container('container');\r\nchart.draw();<\/code><\/pre>\n<p>That\u2019s all we need to do to get an interactive JavaScript-based calendar chart created! Check out this initial version on <a href=\"https:\/\/playground.anychart.com\/lVYS0AHd\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-lVYS0AHd\" src=\"https:\/\/playground.anychart.com\/lVYS0AHd\/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-lVYS0AHd{width:100%;height:850px;}\");\n})();<\/script><\/p>\n<p>Don\u2019t you think this calendar chart looks cool? We can see that Mike Bostock had a huge number of contributions every year, especially in 2017 and 2021. Such an inspiration to code and create more in this new year 2022!<\/p>\n<h2>Advanced Interactive JS Calendar Chart<\/h2>\n<p>It was quite simple and fast to have the basic interactive calendar chart ready. But that\u2019s not all. We can easily customize it to modify the look and feel.<\/p>\n<p>So, let\u2019s make this piece of data visualization even more elegant!<\/p>\n<h3>1. Color customization<\/h3>\n<p>If you look at the contributions graph on GitHub, it uses shades of green to represent the number of contributions made to repositories on a single day. We can try to replicate this look.<\/p>\n<p>Define a custom color scale and set it to render those colors. The color legend can be hidden since the colors represent the ones commonly used for GitHub contributions. Plus, let\u2019s make it all look as in the night theme and add a dark background.<\/p>\n<pre><code class=\"javascript\">\/\/ specify the color of the background\r\nchart.background('#0d1117');\r\n\r\n\/\/ configure a custom color scale\r\nvar customColorScale = anychart.scales.ordinalColor();\r\ncustomColorScale.ranges([\r\n  {equal: 1, color: '#0D4428'},\r\n  {equal: 2, color: '#006D31'},\r\n  {equal: 3, color: '#37AB4B'},\r\n  {equal: 4, color: '#39D353'}\r\n]);\r\n\r\n\/\/ set the custom color scale\r\nchart.colorScale(customColorScale);\r\n\r\n\/\/ hide the color legend\r\nchart.colorRange(false);<\/code><\/pre>\n<h3>2. Stroke, spacing, other aesthetic changes<\/h3>\n<p>We can actually do even better making our chart\u2019s design even more similar to the GitHub contributions calendar graph.<\/p>\n<p>First, remove the month separation line.<\/p>\n<p>Second, adjust the spacing and the stroke for the day tiles and also change the color of those with no data to visually blend it with the background.<\/p>\n<pre><code class=\"javascript\">\/\/ remove the stroke \r\nchart.months()\r\n  .stroke(false)\r\n  .noDataStroke(false);\r\n\r\n\/\/ set the spacing and other options\r\nchart\r\n  .days()\r\n  .spacing(4)\r\n  .stroke(false)\r\n  .noDataStroke(false)\r\n  .noDataFill('#161b22')\r\n  .noDataHatchFill(false);<\/code><\/pre>\n<p>Aha! This makes our JS calendar chart look just like GitHub\u2019s original calendar chart! You can find the interactive version on <a href=\"https:\/\/playground.anychart.com\/PnhpVbPj\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>, with its full HTML\/CSS\/JavaScript code.<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-PnhpVbPj\" src=\"https:\/\/playground.anychart.com\/PnhpVbPj\/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-PnhpVbPj{width:100%;height:810px;}\");\n})();<\/script><\/p>\n<h3>3. Title and tooltip formatting<\/h3>\n<p>Let\u2019s also make the title more striking by modifying the font size, weight, and color.<\/p>\n<pre><code class=\"javascript\">var title = chart.title();\r\ntitle.enabled(true);\r\ntitle\r\n  .text(\"GitHub Contributions of Mike Bostock in 2017\u20132021\")\r\n  .fontSize(22)\r\n  .fontWeight(500)\r\n  .fontColor(\"#dfdfdf\")\r\n  .padding(10);<\/code><\/pre>\n<p>The default tooltip shows the level, a value that defines the color. But why not display the contribution value instead:<\/p>\n<pre><code class=\"javascript\">chart.tooltip()\r\n  .format('{%contributionCount} contributions');<\/code><\/pre>\n<h3>4. Configuring the order of years<\/h3>\n<p>I think it will be better to show more recent years higher. It is not a problem as the order of the years can be reversed very simply with just one line of code.<\/p>\n<pre><code class=\"javascript\">chart.years().inverted(true);<\/code><\/pre>\n<p>Done! Take a look at this stunning JavaScript Calendar Chart. The interactive version with its complete code is on <a href=\"https:\/\/playground.anychart.com\/1G3fgBR2\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-1G3fgBR2\" src=\"https:\/\/playground.anychart.com\/1G3fgBR2\/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-1G3fgBR2{width:100%;height:830px;}\");\n})();<\/script><\/p>\n<h3>5. Final touch<\/h3>\n<p>And the cherry on top.<\/p>\n<p>The classic GitHub calendar chart looks fantastic. But lastly, I decided to modify the color palette to make it all super chic.<\/p>\n<pre><code class=\"javascript\">var customColorScale = anychart.scales.ordinalColor();\r\ncustomColorScale.ranges([\r\n  {equal: 1, color: '#400554'},\r\n  {equal: 2, color: '#693699'},\r\n  {equal: 3, color: '#7c40a9'},\r\n  {equal: 4, color: '#9570dd'}\r\n]);<\/code><\/pre>\n<p>Take a glance at the final chart of this tutorial below. Then feel free to check out this interactive JS calendar graph of Mike Bostock\u2019s GitHub contributions <a href=\"https:\/\/playground.anychart.com\/8RQr8fEy\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a> and to play around with the colors as you want!<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-8RQr8fEy\" src=\"https:\/\/playground.anychart.com\/8RQr8fEy\/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-8RQr8fEy{width:100%;height:830px;}\");c\n})();<\/script><\/p>\n<h2>Conclusion<\/h2>\n<p>To wrap it up, we\u2019ve just seen how to make a seemingly complicated interactive JavaScript calendar chart quite effortlessly. Go ahead and create your own data visualization of this or a <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Supported_Charts_Types\" target=\"_blank\" rel=\"nofollow\">different<\/a> chart type. Please feel free to ask me any questions or drop a suggestion.<\/p>\n<p>As the new year has begun, let\u2019s promise ourselves to create more amazing visualizations and make our GitHub contributions graph look fabulous as well!<\/p>\n<hr \/>\n<p><em>AnyChart thanks freelance data designer Shachee Swadia for creating this amazing JavaScript Calendar Chart tutorial for our blog.<\/em><\/p>\n<p><em>Don&#8217;t miss out on more cool <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a>.<\/em><\/p>\n<p><em>If you want to contribute a guest post, we look forward to <a href=\"https:\/\/www.anychart.com\/support\/\">hearing from you<\/a>.<\/em><\/p>\n<hr \/>\n<p><!-- SyntaxHighlighter --><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/default.min.css\"><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/atom-one-light.min.css\"><script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/highlight.min.js\"><\/script><script>hljs.initHighlightingOnLoad();<\/script><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>A calendar chart is an effective way to represent activity over time graphically. It can nicely display how a quantity varies with the days, weeks, months, and years. If you want to learn to build stylish interactive calendar charts easily using JavaScript, welcome to my step-by-step tutorial! To make this guide not only educating but [&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":[53,260,3272,254,284,127,166,258,3273,2242,3028,471,266,620,54,1389,256,1111,130,165,313,1370,145,1043,3276,3275,3274,3277,3278,32,55,144,36,141,81,57,58,65,56,3271,776,131,459,30,172,2816,1763,804],"class_list":["post-14449","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-anychart","tag-best-data-visualization-examples","tag-calendar-chart","tag-chart","tag-chart-examples","tag-chart-types","tag-charting","tag-charts","tag-contributions-graph","tag-d3","tag-d3-js","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-visualization","tag-data-visualization-best-pracices","tag-data-visualization-examples","tag-data-visualization-practice","tag-data-visualization-weekly","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-dataviz-weekly","tag-github","tag-github-calendar-chart","tag-github-contributions","tag-github-contributions-graph","tag-graphql","tag-graphql-api","tag-html5","tag-html5-charts","tag-infographics","tag-javascript","tag-javascript-charting","tag-javascript-charting-library","tag-javascript-charts","tag-js-chart","tag-js-charting","tag-js-charts","tag-mike-bostock","tag-observable","tag-recap-of-the-week","tag-statistics","tag-tips-and-tricks","tag-tutorial","tag-web-design","tag-web-developers","tag-web-development","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Calendar Chart and How to Create It in JavaScript (HTML5)<\/title>\n<meta name=\"description\" content=\"A calendar chart is an effective way to visualize activity over time. Learn how to build it in JavaScript, exploring Mike Bostock&#039;s contributions on GitHub.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Calendar Chart in JavaScript\" \/>\n<meta property=\"og:description\" content=\"Learn how to build a beautiful interactive Calendar Chart in JavaScript for a web page or app, exploring Mike Bostock&#039;s contributions on GitHub.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/\" \/>\n<meta property=\"og:site_name\" content=\"AnyChart News\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/AnyCharts\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-11T12:24:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-16T06:02:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js-social.png\" \/>\n<meta name=\"author\" content=\"Shachee Swadia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"How to Create Calendar Chart in JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"Learn how to build a beautiful interactive Calendar Chart in JavaScript for a web page or app, exploring Mike Bostock&#039;s contributions on GitHub.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js-social.png\" \/>\n<meta name=\"twitter:creator\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:site\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shachee Swadia\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"How to Create Calendar Chart in JavaScript\",\"datePublished\":\"2022-02-11T12:24:59+00:00\",\"dateModified\":\"2022-08-16T06:02:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/\"},\"wordCount\":1241,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js.png\",\"keywords\":[\"AnyChart\",\"best data visualization examples\",\"calendar chart\",\"chart\",\"chart examples\",\"chart types\",\"charting\",\"charts\",\"contributions graph\",\"D3\",\"D3.js\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"Data Visualization\",\"data visualization best practices\",\"data visualization examples\",\"data visualization practice\",\"data visualization weekly\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"dataviz weekly\",\"GitHub\",\"GitHub Calendar Chart\",\"Github contributions\",\"GitHub contributions graph\",\"GraphQL\",\"GraphQL API\",\"HTML5\",\"html5 charts\",\"infographics\",\"JavaScript\",\"javascript charting\",\"JavaScript charting library\",\"javascript charts\",\"js chart\",\"js charting\",\"js charts\",\"Mike Bostock\",\"Observable\",\"recap of the week\",\"statistics\",\"Tips and tricks\",\"tutorial\",\"web design\",\"web developers\",\"web 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\/2022\/02\/11\/calendar-chart-js\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/\",\"name\":\"Calendar Chart and How to Create It in JavaScript (HTML5)\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js.png\",\"datePublished\":\"2022-02-11T12:24:59+00:00\",\"dateModified\":\"2022-08-16T06:02:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"A calendar chart is an effective way to visualize activity over time. Learn how to build it in JavaScript, exploring Mike Bostock's contributions on GitHub.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js.png\",\"width\":1400,\"height\":799},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Calendar Chart 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":"Calendar Chart and How to Create It in JavaScript (HTML5)","description":"A calendar chart is an effective way to visualize activity over time. Learn how to build it in JavaScript, exploring Mike Bostock's contributions on GitHub.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Calendar Chart in JavaScript","og_description":"Learn how to build a beautiful interactive Calendar Chart in JavaScript for a web page or app, exploring Mike Bostock's contributions on GitHub.","og_url":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2022-02-11T12:24:59+00:00","article_modified_time":"2022-08-16T06:02:31+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js-social.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"How to Create Calendar Chart in JavaScript","twitter_description":"Learn how to build a beautiful interactive Calendar Chart in JavaScript for a web page or app, exploring Mike Bostock's contributions on GitHub.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js-social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"How to Create Calendar Chart in JavaScript","datePublished":"2022-02-11T12:24:59+00:00","dateModified":"2022-08-16T06:02:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/"},"wordCount":1241,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js.png","keywords":["AnyChart","best data visualization examples","calendar chart","chart","chart examples","chart types","charting","charts","contributions graph","D3","D3.js","data analysis","data analytics","data analytics examples","Data Visualization","data visualization best practices","data visualization examples","data visualization practice","data visualization weekly","data visualizations","data visuals","data viz examples","dataviz weekly","GitHub","GitHub Calendar Chart","Github contributions","GitHub contributions graph","GraphQL","GraphQL API","HTML5","html5 charts","infographics","JavaScript","javascript charting","JavaScript charting library","javascript charts","js chart","js charting","js charts","Mike Bostock","Observable","recap of the week","statistics","Tips and tricks","tutorial","web design","web developers","web 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\/2022\/02\/11\/calendar-chart-js\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/","url":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/","name":"Calendar Chart and How to Create It in JavaScript (HTML5)","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js.png","datePublished":"2022-02-11T12:24:59+00:00","dateModified":"2022-08-16T06:02:31+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"A calendar chart is an effective way to visualize activity over time. Learn how to build it in JavaScript, exploring Mike Bostock's contributions on GitHub.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/02\/calendar-chart-js.png","width":1400,"height":799},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2022\/02\/11\/calendar-chart-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Calendar Chart 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\/14449","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=14449"}],"version-history":[{"count":34,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14449\/revisions"}],"predecessor-version":[{"id":15559,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14449\/revisions\/15559"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=14449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=14449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=14449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}