{"id":14464,"date":"2022-03-15T20:37:23","date_gmt":"2022-03-15T20:37:23","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=14464"},"modified":"2022-08-13T11:10:32","modified_gmt":"2022-08-13T11:10:32","slug":"circle-packing-chart-js","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/","title":{"rendered":"How to Build Circle Packing Chart in JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/\"><img decoding=\"async\" class=\"alignnone size-full wp-image-14473\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js.png\" alt=\"Circle Packing Chart Creation in JavaScript: Guide for Data Visualizers and Analysts\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js.png 1500w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js-300x169.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js-768x432.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js-1024x575.png 1024w\" sizes=\"(max-width: 1500px) 100vw, 1500px\" \/><\/a><span style=\"font-size: large;\"><strong><em>A clear step-by-step guide for building an interactive JS Circle Packing Chart to visualize the top 100 most streamed songs on Spotify.<\/em><\/strong><\/span><\/p>\n<p>Want to learn to visualize hierarchical data in stunning circle packing charts that can be added to a web page or app in a hassle-free manner? Don\u2019t feel overwhelmed and just follow my stepwise data visualization tutorial! Using a cool example of data on the top 100 most streamed songs on Spotify, I will show you how to easily create and customize a great-looking interactive circle packing chart with JavaScript.<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>What Is a Circle Packing Chart<\/h2>\n<p>Let me start by giving you a brief about what a circle packing chart is and how it is used.<\/p>\n<p>Also known as a circular tree, a circle packing chart is basically a treemap showcasing hierarchical data, where circles denote nodes and sub-nodes are circles inside the node circle.<\/p>\n<p>The size of the circle denotes the value of the node.<\/p>\n<p>The circular packing representation denotes hierarchy well, providing a convenient visual breakdown by groups and subgroups.<\/p>\n<h2>Previewing the Circle Packing Chart That Will Be Produced<\/h2>\n<p>Take a look at what I am going to build \u2014 the final JS circle packing chart that will be created by the end of the tutorial \u2014 and come along on this musical ride!<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-14472\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js-final.png\" alt=\"The JavaScript-based circle-packing chart built along the tutorial\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js-final.png 1100w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js-final-300x169.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js-final-768x433.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js-final-1024x577.png 1024w\" sizes=\"(max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<h2>Building a JS Circle Packing Chart in 4 Simple Steps<\/h2>\n<p>An embeddable circle packing chart looks exciting but challenging to create. However, there are many <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">JavaScript charting libraries<\/a> specifically designed to help everyone build various data visualizations. And once you\u2019ve found one which provides a built-in circle packing option out of the box, it is usually pretty quick and straightforward to get such an interactive chart conjured up even if you are a beginner with (yet) limited coding skills.<\/p>\n<p>Technically, the steps, which the entire process of creating a circle packing data visualization consists of, remain more or less the same with any JS charting library. In this tutorial, I will be using <a href=\"https:\/\/www.anychart.com\/\">AnyChart<\/a> for illustration. It is pretty easy to start off, with detailed <a href=\"https:\/\/docs.anychart.com\/\" target=\"_blank\" rel=\"nofollow\">documentation<\/a> and many ready-to-use <a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/\">examples<\/a> that can work as a good starting point for quickly building a chart of any type, including this one. Also important, the library is free for non-commercial use.<\/p>\n<p>So, the basic steps to create a JS Circle Packing Chart number four and are as follows:<\/p>\n<ol>\n<li>Make an HTML page for the chart.<\/li>\n<li>Include the necessary JS files.<\/li>\n<li>Add the data.<\/li>\n<li>Write the required JavaScript code for drawing the chart.<\/li>\n<\/ol>\n<h3>1. Create an HTML page<\/h3>\n<p>The first thing I do is create a basic HTML page where the chart will be placed. Next, I create an HTML block element, <code>div<\/code> and assign it an ID attribute like \u201ccontainer\u201d to easily identify it later in the code.<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;meta charset=\"utf-8\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Circle Packing Chart&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0height: 100%; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0margin: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<p>I define the styling of the block such that the chart renders over the whole page by giving the height and width attributes the value of 100%. Feel free to specify it the way you want to do your task, of course.<\/p>\n<h3>2. Include the necessary JavaScript files<\/h3>\n<p>Then, I need to add the scripts I am going to use to create the circle packing chart I want to develop. It is usually possible to reference the necessary files from the CDN of the library you are using or download them to your local machine.<\/p>\n<p>To create this chart in this tutorial, I am employing the AnyChart library. It has a modular structure that makes it easy to only connect the chart types and features you require at the moment, reducing the size of the running JavaScript code. In this case, I need the <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#core\" target=\"_blank\" rel=\"nofollow\">core<\/a> module together with the specific <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#circle_packing\" target=\"_blank\" rel=\"nofollow\">circle packing<\/a> module. So I include both in the <code>head<\/code> section of the HTML page created in the first step.<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;meta charset=\"utf-8\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Circle Packing 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-circle-packing.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-data-adapter.min.js\"&gt;&lt;\/script&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; height: 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\/\/ All the code for the JS Circle Packing Chart will be 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. Add the data<\/h3>\n<p>I decided to visualize the 100 most streamed songs on Spotify using a dedicated dataset from <a href=\"https:\/\/www.kaggle.com\/pavan9065\/top-100-most-streamed-songs-on-spotify\" target=\"_blank\" rel=\"nofollow\">Kaggle<\/a>. I reworked the data a little bit to make it look the way I need and saved it in a <a href=\"https:\/\/gist.githubusercontent.com\/shacheeswadia\/17dc3b3d4ac9b63ac5ac6833944f3a94\/raw\/07c4bec103d22ec2824453a33d41868fd476db3d\/dataPackedCircles.json\" target=\"_blank\" rel=\"nofollow\">JSON file<\/a>.<\/p>\n<p>To load the data from the JSON file, I will utilize a handy module called <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#data_adapter\" target=\"_blank\" rel=\"nofollow\">Data Adapter<\/a>. So I include it in the list of the referenced scripts in the <code>head<\/code> section and use the <code>anychart.data.loadJsonFile<\/code> function to add this data file in the code.<\/p>\n<p>Now that all the preparations are done, let\u2019s get on to the last step for creating this impressive, interactive, JS-based packed circle chart!<\/p>\n<h3>4. Write the JavaScript code for your chart<\/h3>\n<p>Some background knowledge of web development technologies like HTML and JavaScript is always an advantage when creating visualizations and writing code that may seem complicated. However, it can take just as few as about 6 to 7 lines of code to create a circle packing chart this way. So it is not going to be complicated at all anyway. Isn\u2019t that music to your ears?<\/p>\n<p>Initially, I add a function that encloses all the code, ensuring it is executed once the page is ready. Then I include the data inside this function.<\/p>\n<p>Now I define a function with the data parameter and map the data using the <code>data.tree<\/code> function. I add the mapped data to the <code>circlePacking<\/code> function.<\/p>\n<pre><code class=\"javascript\">anychart.onDocumentReady(function () {\r\n  anychart.data.loadJsonFile('https:\/\/gist.githubusercontent.com\/shacheeswadia\/17dc3b3d4ac9b63ac5ac6833944f3a94\/raw\/07c4bec103d22ec2824453a33d41868fd476db3d\/dataPackedCircles.json',\r\n    function(data) {\r\n      var treeData = anychart.data.tree(data, 'as-table');\r\n      var chart = anychart.circlePacking(treeData);\r\n    }\r\n  );\r\n});<\/code><\/pre>\n<p>Finally, I also make a title, add a reference to the previously defined container, and draw the resulting circle packing chart.<\/p>\n<pre><code class=\"javascript\">anychart.onDocumentReady(function () {\r\n  anychart.data.loadJsonFile('https:\/\/gist.githubusercontent.com\/shacheeswadia\/17dc3b3d4ac9b63ac5ac6833944f3a94\/raw\/07c4bec103d22ec2824453a33d41868fd476db3d\/dataPackedCircles.json',\r\n    function(data) {\r\n\r\n      \/\/ add data\r\n      var treeData = anychart.data.tree(data, 'as-table');\r\n\r\n      \/\/ create a circle packing chart instance\r\n      var chart = anychart.circlePacking(treeData);\r\n    \r\n      \/\/ add a chart title\r\n      chart.title(\"Top 100 most streamed songs on Spotify by genre\")\r\n      \r\n      chart.container('container');\r\n      chart.draw();\r\n    \r\n    }\r\n  );\r\n});<\/code><\/pre>\n<p>Tada! A fully functional circle packing chart is built with so little effort!<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-dY0R0BWp\" src=\"https:\/\/playground.anychart.com\/dY0R0BWp\/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-dY0R0BWp{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>The pop genre is clearly visible as the most popular among Spotify\u2019s 100 most streamed songs. I am more of a dance genre person myself, and you may be a rock or rhythm and blues fan. But unsurprisingly, pop and hip-hop are the definite crowd favorites.<\/p>\n<p>You can find the entire code of this basic JavaScript packed circle chart on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/ExwXmOd\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [and on <a href=\"https:\/\/playground.anychart.com\/dY0R0BWp\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.)<\/p>\n<h2>Customizing a JS Circle Packing Chart<\/h2>\n<p>The initial version of this JavaScript-based circle packing chart definitely looks pretty and can be used right away. But I also want to show you some simple ways to make a data visualization of this type even more impressive, stylish, and powerful.<\/p>\n<h3>Color modification<\/h3>\n<p>To add a bit more jazz to the chart, I change the colors of the bubbles. Using one of AnyChart\u2019s pre-built design themes this can be done very easily. I choose the \u201cdark glamour\u201d theme, so I add its script and set the theme in the code.<\/p>\n<pre><code class=\"html\">&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/themes\/dark_glamour.min.js\"&gt;&lt;\/script&gt; \r\n\r\n...\r\n\r\nanychart.theme('darkGlamour');<\/code><\/pre>\n<p>I want to give a transparent background effect to the circles, so I set the background and the fill for the circles as the same color. I thicken the strokes for the circles and set the color of the stroke to the theme color.<\/p>\n<pre><code class=\"javascript\">chart.background('#333');\r\n    \r\nchart.fill('#333');\r\n\r\nchart.stroke(function () {\r\n  return {\r\n    thickness: 2,\r\n    color: this.sourceColor\r\n  };\r\n});<\/code><\/pre>\n<h3>Title improvement<\/h3>\n<p>To make the title more prominent, I use HTML specifying the font size and color. I also add a second line to make a subtitle.<\/p>\n<pre><code class=\"javascript\">chart\r\n  .title()\r\n  .enabled(true)\r\n  .useHtml(true)\r\n  .text(\r\n    '&lt;span style = \"color: #fff; font-size:20px;\"&gt;Top 100 most streamed songs by genre&lt;\/span&gt;' +\r\n    '&lt;br\/&gt;&lt;span style=\"color:#1db954; font-size: 18px;\"&gt;(Based on the number of Spotify Streams)&lt;\/span&gt;'\r\n  );<\/code><\/pre>\n<p>Check out this customized version of the JS packed circles chart <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/MWEomxQ\" target=\"_blank\" rel=\"nofollow\">here<\/a> [or on <a href=\"https:\/\/playground.anychart.com\/3MO3NENz\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.]<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-3MO3NENz\" src=\"https:\/\/playground.anychart.com\/3MO3NENz\/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-3MO3NENz{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<h3>Tooltip formatting<\/h3>\n<p>One of the best ways to make an interactive data visualization more informative is to add more details to the tooltip. The dataset contains information about the artist and the year of each song, along with its popularity value. So I include all this information in the tooltip of the circle packing chart using HTML.<\/p>\n<pre><code class=\"javascript\">chart\r\n  .tooltip()\r\n  .useHtml(true)\r\n  .titleFormat('{%name}')\r\n  .format( function(){\r\n    let dataValue = this.item.ka;\r\n    if(this.depth == 2){ \r\n      return '&lt;span style = font-size:14px;\"&gt;Popularity Value - ' + dataValue.value + '&lt;\/span&gt;' +\r\n      '&lt;br\/&gt;lt;span style = font-size:14px;\"&gt;Artist - ' + dataValue.artist + '&lt;\/span&gt;' + \r\n      '&lt;br\/&gt;&lt;span style = font-size:14px;\"&gt;Year - ' + dataValue.year + '&lt;\/span&gt;'  \r\n    }else{\r\n      return '&lt;span style = \"color: #fff; font-size:14px;\"&gt;Popularity Value - ' + this.value + '&lt;\/span&gt;'\r\n    }\r\n  });<\/code><\/pre>\n<p>That\u2019s all! An elegant and enlightening JavaScript Circle Packing Chart is designed and ready to serve.<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-OhusPMBK\" src=\"https:\/\/playground.anychart.com\/OhusPMBK\/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-OhusPMBK{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>Check out the entire code with all the customizations on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/rNGwwYb\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a> [or on <a href=\"https:\/\/playground.anychart.com\/OhusPMBK\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.]<\/p>\n<h2>Conclusion<\/h2>\n<p>You can see how building a creative chart like the packed circles is so uncomplicated. There are tons of different types of data visualization that you can learn to create using various <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">JS charting libraries<\/a>. Or start by looking into other <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Supported_Charts_Types\" target=\"_blank\" rel=\"nofollow\">chart options<\/a> available in AnyChart.<\/p>\n<p>Let me know if you have any questions about building this chart or any other doubts. Music is good for the soul and creating visualizations is good for the mind, so let\u2019s listen to more songs and build more charts!<\/p>\n<hr \/>\n<p><em>Published with the permission of Shachee Swadia. Originally appeared on <a href=\"https:\/\/levelup.gitconnected.com\/how-to-create-a-circle-packing-chart-using-javascript-6771648882cc\" target=\"_blank\" rel=\"nofollow\">Level Up Coding<\/a> with the title <em>&#8220;How to Create a Circle Packing Chart Using JavaScript&#8221;<\/em> on January 3, 2022.<\/p>\n<p>Don&#8217;t miss out on our other <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a>.<\/p>\n<p>If you have an idea for an interesting guest post, you&#8217;re more than welcome to <a href=\"https:\/\/www.anychart.com\/support\/\">let us know<\/a> about it!<\/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 clear step-by-step guide for building an interactive JS Circle Packing Chart to visualize the top 100 most streamed songs on Spotify. Want to learn to visualize hierarchical data in stunning circle packing charts that can be added to a web page or app in a hassle-free manner? Don\u2019t feel overwhelmed and just follow my [&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,561,265,267,3219,268,1758,3149,284,127,258,2937,471,266,620,2220,2838,54,1389,1760,2757,256,1111,350,844,165,313,1370,133,775,805,1154,1762,2013,2014,32,55,144,167,433,152,2949,151,36,907,141,249,81,57,1238,142,96,99,58,65,56,101,1937,2335,1938,318,2605,2604,2744,2599,2600,2602,459,2603,3082,30,2224,172,1939,2015,2816,1763,804],"class_list":["post-14464","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-visualizations","tag-big-data","tag-big-data-applications","tag-big-data-apps","tag-big-data-tools","tag-chart-design","tag-chart-development","tag-chart-examples","tag-chart-types","tag-charts","tag-circle-packing","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-visual","tag-data-visualisation","tag-data-visualization","tag-data-visualization-best-pracices","tag-data-visualization-design","tag-data-visualization-development","tag-data-visualization-examples","tag-data-visualization-practice","tag-data-visualization-projects","tag-data-visualization-tutorial","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-dataviz","tag-dataviz-projects","tag-front-end-development","tag-good-data-visualization","tag-guest-post","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-infographics","tag-interactive-charts","tag-interactive-graphics","tag-interactive-infographic","tag-interactive-infographics","tag-interactive-visualizations","tag-javascript","tag-javascript-chart-tutorial","tag-javascript-charting","tag-javascript-charting-api","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-graph","tag-javascript-graphics","tag-javascript-graphics-library","tag-javascript-library","tag-js-chart","tag-js-charting","tag-js-charts","tag-js-graphics","tag-json","tag-json-charts","tag-json-data-visualization","tag-music","tag-music-apps","tag-music-streaming-apps","tag-packed-circles","tag-spotify","tag-spotify-data","tag-spotify-statistics","tag-statistics","tag-streaming","tag-streaming-platforms","tag-tips-and-tricks","tag-tree-data","tag-tutorial","tag-visualizing-json-data","tag-web-charts","tag-web-design","tag-web-developers","tag-web-development","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Circle Packing Chart Creation in JavaScript \u2014 Guide for Data Visualizers<\/title>\n<meta name=\"description\" content=\"A clear step-by-step guide for building an interactive Circle Packing Chart using JavaScript HTML5 to visualize the top 100 most streamed songs on Spotify.\" \/>\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\/03\/15\/circle-packing-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 Build Circle Packing Chart in JavaScript\" \/>\n<meta property=\"og:description\" content=\"A step-by-step guide for building an interactive JS Circle Packing Chart to visualize the 100 most streamed songs on Spotify.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-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-03-15T20:37:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-13T11:10:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/03\/circle-packing-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 Build Circle Packing Chart in JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"A step-by-step guide for building an interactive JS Circle Packing Chart to visualize the 100 most streamed songs on Spotify.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/03\/circle-packing-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=\"9 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\/03\/15\/circle-packing-chart-js\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"How to Build Circle Packing Chart in JavaScript\",\"datePublished\":\"2022-03-15T20:37:23+00:00\",\"dateModified\":\"2022-08-13T11:10:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/\"},\"wordCount\":1382,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js.png\",\"keywords\":[\"advanced data visualization\",\"AnyChart\",\"app development\",\"best data visualization examples\",\"best data visualizations\",\"big data\",\"big data applications\",\"big data apps\",\"big data tools\",\"chart design\",\"chart development\",\"chart examples\",\"chart types\",\"charts\",\"circle packing\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data visual\",\"data visualisation\",\"Data Visualization\",\"data visualization best practices\",\"data visualization design\",\"data visualization development\",\"data visualization examples\",\"data visualization practice\",\"data visualization projects\",\"data visualization tutorial\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"dataviz\",\"dataviz projects\",\"front-end development\",\"good data visualization\",\"guest post\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"infographics\",\"interactive charts\",\"interactive graphics\",\"interactive infographic\",\"interactive infographics\",\"interactive visualizations\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"javascript charting api\",\"JavaScript charting library\",\"javascript charts\",\"javascript graph\",\"javascript graphics\",\"JavaScript graphics library\",\"JavaScript library\",\"js chart\",\"js charting\",\"js charts\",\"JS graphics\",\"JSON\",\"JSON charts\",\"JSON data visualization\",\"music\",\"music apps\",\"music streaming apps\",\"packed circles\",\"Spotify\",\"Spotify data\",\"Spotify statistics\",\"statistics\",\"streaming\",\"streaming platforms\",\"Tips and tricks\",\"tree data\",\"tutorial\",\"visualizing JSON data\",\"web charts\",\"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\/03\/15\/circle-packing-chart-js\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/\",\"name\":\"Circle Packing Chart Creation in JavaScript \u2014 Guide for Data Visualizers\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js.png\",\"datePublished\":\"2022-03-15T20:37:23+00:00\",\"dateModified\":\"2022-08-13T11:10:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"A clear step-by-step guide for building an interactive Circle Packing Chart using JavaScript HTML5 to visualize the top 100 most streamed songs on Spotify.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js.png\",\"width\":1500,\"height\":843},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Build Circle Packing 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":"Circle Packing Chart Creation in JavaScript \u2014 Guide for Data Visualizers","description":"A clear step-by-step guide for building an interactive Circle Packing Chart using JavaScript HTML5 to visualize the top 100 most streamed songs on Spotify.","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\/03\/15\/circle-packing-chart-js\/","og_locale":"en_US","og_type":"article","og_title":"How to Build Circle Packing Chart in JavaScript","og_description":"A step-by-step guide for building an interactive JS Circle Packing Chart to visualize the 100 most streamed songs on Spotify.","og_url":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2022-03-15T20:37:23+00:00","article_modified_time":"2022-08-13T11:10:32+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/03\/circle-packing-chart-js-social.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"How to Build Circle Packing Chart in JavaScript","twitter_description":"A step-by-step guide for building an interactive JS Circle Packing Chart to visualize the 100 most streamed songs on Spotify.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/03\/circle-packing-chart-js-social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"How to Build Circle Packing Chart in JavaScript","datePublished":"2022-03-15T20:37:23+00:00","dateModified":"2022-08-13T11:10:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/"},"wordCount":1382,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js.png","keywords":["advanced data visualization","AnyChart","app development","best data visualization examples","best data visualizations","big data","big data applications","big data apps","big data tools","chart design","chart development","chart examples","chart types","charts","circle packing","data analysis","data analytics","data analytics examples","data visual","data visualisation","Data Visualization","data visualization best practices","data visualization design","data visualization development","data visualization examples","data visualization practice","data visualization projects","data visualization tutorial","data visualizations","data visuals","data viz examples","dataviz","dataviz projects","front-end development","good data visualization","guest post","HTML","HTML charts","HTML5","html5 charts","infographics","interactive charts","interactive graphics","interactive infographic","interactive infographics","interactive visualizations","JavaScript","javascript chart tutorial","javascript charting","javascript charting api","JavaScript charting library","javascript charts","javascript graph","javascript graphics","JavaScript graphics library","JavaScript library","js chart","js charting","js charts","JS graphics","JSON","JSON charts","JSON data visualization","music","music apps","music streaming apps","packed circles","Spotify","Spotify data","Spotify statistics","statistics","streaming","streaming platforms","Tips and tricks","tree data","tutorial","visualizing JSON data","web charts","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\/03\/15\/circle-packing-chart-js\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/","url":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/","name":"Circle Packing Chart Creation in JavaScript \u2014 Guide for Data Visualizers","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js.png","datePublished":"2022-03-15T20:37:23+00:00","dateModified":"2022-08-13T11:10:32+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"A clear step-by-step guide for building an interactive Circle Packing Chart using JavaScript HTML5 to visualize the top 100 most streamed songs on Spotify.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/01\/circle-packing-chart-js.png","width":1500,"height":843},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2022\/03\/15\/circle-packing-chart-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Build Circle Packing 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\/14464","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=14464"}],"version-history":[{"count":18,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14464\/revisions"}],"predecessor-version":[{"id":15525,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14464\/revisions\/15525"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=14464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=14464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=14464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}