{"id":15535,"date":"2022-08-15T11:36:17","date_gmt":"2022-08-15T11:36:17","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=15535"},"modified":"2022-09-08T14:44:53","modified_gmt":"2022-09-08T14:44:53","slug":"mosaic-plot","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/","title":{"rendered":"How to Create Mosaic Plot with JavaScript"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot.png\" alt=\"Mosaic plot on a web page or app\" width=\"100%\" class=\"alignnone size-full wp-image-15549\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot.png 1400w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-300x169.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-768x432.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-1024x576.png 1024w\" sizes=\"(max-width: 1400px) 100vw, 1400px\" \/><\/a><strong>Have you heard of a mosaic plot?<\/strong> It is a very interesting chart type designed to facilitate exploring relationships between variables. Mosaic plots (also known as mosaic charts) visualize data in rectangular tiles whose width encodes one variable and height the other.<\/p>\n<p>If you\u2019d like to learn how to create such an elegant diagram with ease, follow me as I will show you the ropes right now! Along this tutorial, I will be building an interactive mosaic plot of social media adoption in the United States by age group and year, using JavaScript and explaining every step in detail.<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>Mosaic Plot to Be Built<\/h2>\n<p>To get you in the mood for some creative work ahead, I invite you to take a sneak peek at the final mosaic plot that will be completed at the end of the article. And it\u2019s time to get the ball rolling!<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-javascript.png\" alt=\"JavaScript-based mosaic plot being created\" width=\"100%\" class=\"alignnone size-full wp-image-15550\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-javascript.png 1160w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-javascript-300x177.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-javascript-768x454.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-javascript-1024x605.png 1024w\" sizes=\"(max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<h2>Basic Mosaic Plot<\/h2>\n<p>If you have ever created any charts with JavaScript, you already possess an understanding of how it works. In that case, you simply <a href=\"https:\/\/www.anychart.com\/blog\/2017\/03\/05\/how-to-choose-the-right-javascript-charting-component-10-factors-you-have-to-consider\/\">choose a JS charting library<\/a> and follow its <a href=\"https:\/\/docs.anychart.com\/Basic_Charts\/Marimekko_Chart\/Mosaic_Chart\" target=\"_blank\" rel=\"nofollow\">mosaic plot documentation<\/a>. But if it is going to be your first such experience (or your previous one was not too easy and exciting), this tutorial is exactly for you!<\/p>\n<p>Let\u2019s begin with defining the steps that should be taken. Generally speaking, literally any cool interactive JS-based data visualization, including a mosaic plot, is built in four fundamental moves:<\/p>\n<ol>\n<li>Get a web page for your chart to be put on.<\/li>\n<li>Reference JavaScript files to be used.<\/li>\n<li>Set data to be visualized.<\/li>\n<li>Write some JS code for producing the plot you need.<\/li>\n<\/ol>\n<p>Now, join me as I delve into each!<\/p>\n<h3>1. Get a web page<\/h3>\n<p>First things first. I create a basic HTML page. In the <code>&lt;body&gt;<\/code> section, I include a block-level element, <code>&lt;div&gt;<\/code>, which will be the location where the mosaic plot will be rendered, and provide it with a unique <code>id<\/code> attribute, <code>container<\/code> in this case. I also set its height and width settings as 100% as I want to see the mosaic plot stretched along the whole web page.<\/p>\n<p>Here is how my HTML page looks:<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;Mosaic Plot in JS&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%; 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&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>2. Reference JavaScript files<\/h3>\n<p>Now, it\u2019s time to load scripts that will be used to create the intended mosaic plot on the web page.<\/p>\n<p>Here, I will be using the <a href=\"https:\/\/www.anychart.com\">JS charting library<\/a> of AnyChart. It\u2019s feature-rich, with comprehensive <a href=\"https:\/\/docs.anychart.com\" target=\"_blank\" rel=\"nofollow\">documentation<\/a> and <a href=\"https:\/\/api.anychart.com\/\" target=\"_blank\" rel=\"nofollow\">API reference<\/a>, and numerous readymade examples in the <a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/\">gallery<\/a>. Also, AnyChart is modular, which means one can connect only a couple of lightweight scripts to power the features that are actually needed instead of unnecessarily overloading a web page or app with the whole library.<\/p>\n<p>A mosaic plot requires two modules: <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#mekko\" target=\"_blank\" rel=\"nofollow\">Mekko<\/a>. I add them to the page by including the following in the <code>&lt;head&gt;<\/code> section:<\/p>\n<pre><code class=\"html\">&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-mekko.min.js\"&gt;&lt;\/script&gt;\r\n<\/code><\/pre>\n<p>I also put a <code>&lt;script&gt;<\/code>\u00a0tag in the <code>&lt;body&gt;<\/code> section. (Or it can go to the <code>&lt;head&gt;<\/code> section. Doesn\u2019t really matter.) That\u2019s where the full JavaScript code of my upcoming mosaic plot will be placed.<\/p>\n<p>Here\u2019s what I\u2019ve got at this point:<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;Mosaic Plot in JS&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-mekko.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; 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\/\/ The JS mosaic plotting code will come here.\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/code><\/pre>\n<h3>3. Set data<\/h3>\n<p>Then comes data. As I pointed out in the introduction, I want to look at social media adoption in the U.S. Nowadays, about three-quarters of all American adults are reported to use at least\u00a0one social media site. Let\u2019s take a deeper dive and explore the situation across different age groups and years \u2014 it\u2019s going to be a cool example of a mosaic plot in action!<\/p>\n<p>The data I will be visualizing is from <a href=\"https:\/\/www.pewresearch.org\/internet\/fact-sheet\/social-media\/?menuItem=81867c91-92ad-45b8-a964-a2a894f873ef\" target=\"_blank\" rel=\"nofollow\">Pew Research Center<\/a>. It does not look complicated, so I will add it directly to the code. Pay attention to the format of the data because that\u2019s how the mosaic plot \u201cunderstands\u201d what to represent on which axis.<\/p>\n<pre><code class=\"javascript\">let data = {\r\n  header: ['#', '2006', '2009', '2012', '2015', '2018', '2021'],\r\n  rows: [\r\n    ['18\u201329', 41, 70, 81, 90, 88, 84],\r\n    ['30\u201349', 6, 42, 64, 77, 78, 81],\r\n    ['50\u201364', 3, 20, 39, 51, 64, 73],\r\n    ['65+', 0, 5, 16, 35, 37, 45]\r\n  ]\r\n};<\/code><\/pre>\n<h3>4. Write some JS code<\/h3>\n<p>I\u2019ve got a place for my mosaic plot, scripts to draw it, and data that needs to be visualized. Now that those things are all set, I will do some quick JavaScript coding within the <code>&lt;script&gt;<\/code> tag.<\/p>\n<p>The very first thing I do here is add the <code>anychart.onDocumentReady()<\/code> function. Everything else will go inside of it and will be executed after the web page is fully loaded.<\/p>\n<pre><code class=\"html\">&lt;script&gt;\r\n\u00a0\u00a0anychart.onDocumentReady(function () {\r\n\u00a0\u00a0\u00a0\u00a0\/\/ The JS mosaic plotting code will come here.\r\n\u00a0\u00a0});\r\n&lt;\/script&gt;<\/code><\/pre>\n<p>Then I add the data from the previous step:<\/p>\n<pre><code class=\"javascript\">anychart.onDocumentReady(function () {\r\n\r\n  let data = {\r\n    header: ['#', '2006', '2009', '2012', '2015', '2018', '2021'],\r\n    rows: [\r\n      ['18\u201329', 41, 70, 81, 90, 88, 84],\r\n      ['30\u201349', 6, 42, 64, 77, 78, 81],\r\n      ['50\u201364', 3, 20, 39, 51, 64, 73],\r\n      ['65+', 0, 5, 16, 35, 37, 45]\r\n    ]\r\n  };\r\n\r\n});<\/code><\/pre>\n<p>Then, inside the same function, I create an instance of a mosaic plot:<\/p>\n<pre><code class=\"javascript\">let chart = anychart.mosaic();<\/code><\/pre>\n<p>And load the data to it:<\/p>\n<pre><code class=\"javascript\">chart.data(data);<\/code><\/pre>\n<p>I also add a title for the entire mosaic plot:<\/p>\n<pre><code class=\"javascript\">chart.title(\"Social Media Use in U.S. by Age\");<\/code><\/pre>\n<p>Finally, I define where to put the visualization by specifying the ID of the <code>&lt;div&gt;<\/code> element (see step 1) and draw the resulting mosaic plot.<\/p>\n<pre><code class=\"javascript\">chart.container('container');\r\nchart.draw();<\/code><\/pre>\n<p>Here is how the entire JavaScript code of my mosaic plot looks:<\/p>\n<pre><code class=\"javascript\">anychart.onDocumentReady(function () {\r\n  \r\n  \/\/ set the data to visualize\r\n  let data = {\r\n    header: ['#', '2006', '2009', '2012', '2015', '2018', '2021'],\r\n    rows: [\r\n      ['18\u201329', 41, 70, 81, 90, 88, 84],\r\n      ['30\u201349', 6, 42, 64, 77, 78, 81],\r\n      ['50\u201364', 3, 20, 39, 51, 64, 73],\r\n      ['65+', 0, 5, 16, 35, 37, 45]\r\n    ]\r\n  };\r\n\r\n  \/\/ create a mosaic plot\r\n  let chart = anychart.mosaic();\r\n  \r\n  \/\/ load the data to the plot\r\n  chart.data(data);\r\n\r\n  \/\/ set the plot title\r\n  chart.title(\"Social Media Use in U.S. by Age\");\r\n  \r\n  \/\/ set the mosaic chart container element id\r\n  chart.container('container');\r\n  \r\n  \/\/ draw the resulting chart\r\n  chart.draw();\r\n  \r\n});<\/code><\/pre>\n<p>Bingo! A basic mosaic plot is ready in that few lines of code!<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-1xYCN7zI\" src=\"https:\/\/playground.anychart.com\/1xYCN7zI\/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-1xYCN7zI{width:100%;height:800px;}\");\n})();<\/script><\/p>\n<p>We can immediately see that a higher percentage of people in the youngest age group use social media than in any other. Well, one could expect it. But look at how much more people in the other age groups use social media now compared to 10 or 15 years ago. See what else you can notice.<\/p>\n<p>Check out this basic mosaic plot on <a href=\"https:\/\/playground.anychart.com\/1xYCN7zI\" target=\"_blank\" rel=\"nofollow\"><span style=\"font-weight: 400;\">AnyChart Playground<\/span><\/a>. Just in case, the full code is also right below:<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;Mosaic Plot in JS&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-mekko.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; 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\r\n      anychart.onDocumentReady(function () {\r\n  \r\n        \/\/ set the data to visualize\r\n        let data = {\r\n          header: ['#', '2006', '2009', '2012', '2015', '2018', '2021'],\r\n          rows: [\r\n            ['18\u201329', 41, 70, 81, 90, 88, 84],\r\n            ['30\u201349', 6, 42, 64, 77, 78, 81],\r\n            ['50\u201364', 3, 20, 39, 51, 64, 73],\r\n            ['65+', 0, 5, 16, 35, 37, 45]\r\n          ]\r\n        };\r\n\r\n        \/\/ create a mosaic plot\r\n        let chart = anychart.mosaic();\r\n  \r\n        \/\/ load the data to the plot\r\n        chart.data(data);\r\n\r\n        \/\/ set the plot title\r\n        chart.title(\"Social Media Use in U.S. by Age\");\r\n  \r\n        \/\/ set the mosaic chart container element id\r\n        chart.container('container');\r\n  \r\n        \/\/ draw the resulting chart\r\n        chart.draw();\r\n  \r\n      });\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/code><\/pre>\n<h2>Advanced Mosaic Plot<\/h2>\n<p>The mosaic plot built in the previous part of the tutorial is based on the default settings for this chart type configured in the AnyChart JS charting library. But there are also various options to tweak the visualization. Now, come along as I harness the power of customization to make my mosaic plot more stylish and informative.<\/p>\n<h3>1. Change the mosaic plot design theme<\/h3>\n<p>First, I want to make the colors of the mosaic plot more sophisticated and use some pastel shades. AnyChart provides a range of pre-built <a href=\"https:\/\/docs.anychart.com\/Appearance_Settings\/Themes\" target=\"_blank\" rel=\"nofollow\"><span style=\"font-weight: 400;\">chart design themes<\/span><\/a>. Among them is a beautiful pastel one that I am going to apply right away. To do that, I load the dedicated JS file by adding a link to it in the <code>&lt;head&gt;<\/code> section:<\/p>\n<pre><code class=\"html\">&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/themes\/pastel.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\n<p>And set the theme in the JS code:<\/p>\n<pre><code class=\"javascript\">anychart.theme(\"pastel\");<\/code><\/pre>\n<h3>2. Enhance the mosaic plot labels<\/h3>\n<p>Second, I improve the font styling in the mosaic plot labels using HTML and add the percent sign % to make it clear that these values are percentages:<\/p>\n<pre><code class=\"javascript\">chart.labels()\r\n  .useHtml(true)\r\n  .format(\"&lt;span style='font-size:12px; font-weight:700; color: #786b61;'&gt;{%value}%&lt;\/span&gt;\");<\/code><\/pre>\n<h3>3. Adjust the mosaic plot tile spacing<\/h3>\n<p>Third, I decrease the spacing between the tiles. Since the chart colors are now lighter, that will further beautify the mosaic chart and also provide more room for the labels shown in the tiles.<\/p>\n<pre><code class=\"javascript\">chart.pointsPadding(3);<\/code><\/pre>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-sWKDIYAc\" src=\"https:\/\/playground.anychart.com\/sWKDIYAc\/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-sWKDIYAc{width:100%;height:800px;}\");\n})();<\/script><\/p>\n<p>Take a look at this customized version of the mosaic plot with its full code on <a href=\"https:\/\/playground.anychart.com\/sWKDIYAc\" target=\"_blank\" rel=\"nofollow\"><span style=\"font-weight: 400;\">AnyChart Playground<\/span><\/a>.<\/p>\n<h3>4. Improve the mosaic plot title<\/h3>\n<p>Fourth, I modify the appearance of the title. HTML is there to help me customize the font and add a subtitle.<\/p>\n<pre><code class=\"javascript\">chart\r\n  .title()\r\n  .enabled(true)\r\n  .useHtml(true)\r\n  .text(\"&lt;span style = 'font-size:16px; font-weight:600;'&gt;Social Media Use in U.S. by Age&lt;\/span&gt;&lt;br&gt;&lt;span style = 'font-size:14px;'&gt;Share of U.S. adults saying they use at least one social media platform&lt;\/span&gt;\");<\/code><\/pre>\n<h3>5. Enhance the mosaic plot tooltip<\/h3>\n<p>Fifth and finally, I change the tooltip content to make it more informative. In the title of the tooltip, I display the year, and in the main part, an explaining sentence with the percentage and age group instead of raw numbers shown by default.<\/p>\n<pre><code class=\"javascript\">let tooltip = chart.tooltip();\r\ntooltip\r\n\u00a0\u00a0.useHtml(true)\r\n\u00a0\u00a0.titleFormat(\"&lt;b&gt;&lt;span style='font-size:15px;'&gt;{%SeriesName}&lt;\/b&gt;\")\r\n\u00a0\u00a0.format(\"&lt;span style='font-size:13px;'&gt;&lt;b&gt;{%value}%&lt;\/b&gt; of people aged &lt;b&gt;{%x}&lt;\/b&gt; said they&lt;br&gt; used at least one social media platform&lt;\/span&gt;\");\r\n<\/code><\/pre>\n<p>So, how do you like the final mosaic plot of the tutorial with all these customizations?<\/p>\n<p><iframe loading=\"lazy\" class=\"anychart-embed anychart-embed-JKwucBGM\" src=\"https:\/\/playground.anychart.com\/d0G2JcXJ\/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-JKwucBGM{width:100%;height:800px;}\");\n})();<\/script><\/p>\n<p>See this final version of the mosaic plot with the full source code on <a href=\"https:\/\/playground.anychart.com\/d0G2JcXJ\" target=\"_blank\" rel=\"nofollow\"><span style=\"font-weight: 400;\">AnyChart Playground<\/span><\/a>.<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;Mosaic Plot in JS&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-mekko.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/themes\/pastel.js\u201d&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; 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\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.onDocumentReady(function () {\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the data to visualize\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0let data = {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0header: ['#', '2006', '2009', '2012', '2015', '2018', '2021'],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0rows: [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0['18\u201329', 41, 70, 81, 90, 88, 84],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0['30\u201349', 6, 42, 64, 77, 78, 81],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0['50\u201364', 3, 20, 39, 51, 64, 73],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0['65+', 0, 5, 16, 35, 37, 45]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0};\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create a mosaic plot\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0let chart = anychart.mosaic();\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set one of the pre-built design themes\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.theme(\"pastel\");\t\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ load the data to the plot\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.data(data);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ configure the label settings\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.labels()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.useHtml(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.format(\"&lt;span style='font-size:12px; font-weight:700; color: #786b61;'&gt;{%value}%&lt;\/span&gt;\");\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the padding between the points\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.pointsPadding(3);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the plot title  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.title()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.enabled(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.useHtml(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.text(\"&lt;span style = 'font-size:16px; font-weight:600;'&gt;Social Media Use in U.S. by Age&lt;\/span&gt;&lt;br&gt;&lt;span style = 'font-size:14px;'&gt;Share of U.S. adults saying they use at least one social media platform&lt;\/span&gt;\");\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ format the tooltip using html\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0let tooltip = chart.tooltip();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0tooltip\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.useHtml(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.titleFormat(\"&lt;b&gt;&lt;span style='font-size:15px;'&gt;{%SeriesName}&lt;\/b&gt;\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.format(\"&lt;span style='font-size:13px;'&gt;&lt;b&gt;{%value}%&lt;\/b&gt; of people aged &lt;b&gt;{%x}&lt;\/b&gt; said they&lt;br&gt; used at least one social media platform&lt;\/span&gt;\");\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the mosaic chart container id\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.container('container');\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ draw the resulting chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.draw();\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>I hope you enjoyed this tutorial and realized how easy it is to build a great-looking, interactive mosaic plot. Working knowledge of HTML and JavaScript is always helpful in such tasks. But now you see it is not too necessary as everything can be quite straightforward and largely intuitive.<\/p>\n<p>Now it\u2019s your turn! Go make your own mosaic chart to apply your newly acquired skills. Or learn <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\"><span style=\"font-weight: 400;\">how to create a JavaScript chart<\/span><\/a> of some other <a href=\"https:\/\/docs.anychart.com\/Basic_Charts\/Marimekko_Chart\/Mosaic_Chart\" target=\"_blank\" rel=\"nofollow\">type<\/a>. Of course, don\u2019t forget to share your data visualizations on a social media platform of your choice!<\/p>\n<hr \/>\n<p><strong><em>Many thanks to Shachee Swadia for making this amazing mosaic plot guide for our blog!<\/p>\n<p>Check out more <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a>.<\/p>\n<p>Would you like to create a guest post for our blog? <a href=\"https:\/\/www.anychart.com\/support\/\">Let us know<\/a>!<\/em><\/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>Have you heard of a mosaic plot? It is a very interesting chart type designed to facilitate exploring relationships between variables. Mosaic plots (also known as mosaic charts) visualize data in rectangular tiles whose width encodes one variable and height the other. If you\u2019d like to learn how to create such an elegant diagram with [&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,23,13,279,4],"tags":[843,619,618,53,289,3173,1622,260,2000,847,1621,268,1758,3149,284,166,258,282,471,266,620,916,1292,880,806,194,193,1759,3352,509,291,294,2220,2838,54,1389,1760,2757,256,1111,1379,844,130,165,313,1370,743,133,774,145,2032,1498,805,2013,2014,32,55,1335,144,2979,2016,167,146,433,152,2949,151,36,907,141,249,3111,81,57,169,170,1238,142,96,99,2398,58,65,56,101,2227,240,2228,241,2368,3424,3423,962,2653,3422,3421,2671,3260,459,1226,3099,1310,782,1331,30,846,172,309,807,808,3100,293,2816,1763,804,3406,3407],"class_list":["post-15535","post","type-post","status-publish","format-standard","hentry","category-anychart-charting-component","category-html5","category-javascript","category-javascript-chart-tutorials","category-tips-and-tricks","tag-advanced-data-visualization","tag-analysis","tag-analytics","tag-anychart","tag-api","tag-app-development","tag-best-bi-tools","tag-best-data-visualization-examples","tag-best-data-visualization-tool","tag-best-data-visualization-tools","tag-bi-tools","tag-big-data-tools","tag-chart-design","tag-chart-development","tag-chart-examples","tag-charting","tag-charts","tag-data","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-api","tag-data-chart","tag-data-charting","tag-data-charts","tag-data-comparison","tag-data-composition","tag-data-design","tag-data-graphic","tag-data-graphics","tag-data-journalism","tag-data-science","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-tool","tag-data-visualization-tutorial","tag-data-visualization-weekly","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-data-viz","tag-dataviz","tag-dataviz-examples","tag-dataviz-weekly","tag-drawing-tools","tag-example","tag-front-end-development","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-infographic","tag-infographics","tag-information-graphics","tag-information-visualization","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-features","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-drawing","tag-javascript-drawing-library","tag-javascript-graph","tag-javascript-graphics","tag-javascript-graphics-library","tag-javascript-library","tag-javascript-mapping-library","tag-js-chart","tag-js-charting","tag-js-charts","tag-js-graphics","tag-marimekko-chart","tag-mekko-chart","tag-mekko-graphics","tag-mosaic-chart","tag-mosaic-plot","tag-part-to-whole-relationships","tag-pew-research","tag-pew-research-center","tag-plotting","tag-social-media-adoption","tag-social-media-use","tag-social-vulnerability-index","tag-statistic","tag-statistics","tag-statistics-visualization","tag-storytelling-examples","tag-survey","tag-survey-data","tag-survey-data-visualization","tag-tips-and-tricks","tag-top-data-visualization-tools","tag-tutorial","tag-united-states","tag-visual-analysis","tag-visual-analytics","tag-visual-storytelling-examples","tag-visualization","tag-web-design","tag-web-developers","tag-web-development","tag-website","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>Mosaic Plot: Learn How to Create It for Web with JavaScript (HTML5)<\/title>\n<meta name=\"description\" content=\"See what a mosaic plot is, and learn how to create this chart with JavaScript for a web page or app, in this detailed, yet simple data viz tutorial.\" \/>\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\/08\/15\/mosaic-plot\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Mosaic Plot for Web with JavaScript\" \/>\n<meta property=\"og:description\" content=\"See what a mosaic plot is and learn how to create one with JavaScript for any web page or app.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/\" \/>\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-08-15T11:36:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-08T14:44:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-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 Mosaic Plot for Web with JavaScript\" \/>\n<meta name=\"twitter:description\" content=\"See what a mosaic plot is and learn how to create one with JavaScript for any web page or app.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-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=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"How to Create Mosaic Plot with JavaScript\",\"datePublished\":\"2022-08-15T11:36:17+00:00\",\"dateModified\":\"2022-09-08T14:44:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/\"},\"wordCount\":1324,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot.png\",\"keywords\":[\"advanced data visualization\",\"analysis\",\"analytics\",\"AnyChart\",\"api\",\"app development\",\"best BI tools\",\"best data visualization examples\",\"best data visualization tool\",\"best data visualization tools\",\"BI tools\",\"big data tools\",\"chart design\",\"chart development\",\"chart examples\",\"charting\",\"charts\",\"data\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data API\",\"data chart\",\"data charting\",\"data charts\",\"data comparison\",\"data composition\",\"data design\",\"data graphic\",\"data graphics\",\"data journalism\",\"data science\",\"data visual\",\"data visualisation\",\"Data Visualization\",\"data visualization best practices\",\"data visualization design\",\"data visualization development\",\"data visualization examples\",\"data visualization practice\",\"data visualization tool\",\"data visualization tutorial\",\"data visualization weekly\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"data-viz\",\"dataviz\",\"dataviz examples\",\"dataviz weekly\",\"drawing tools\",\"example\",\"front-end development\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"infographic\",\"infographics\",\"information graphics\",\"information visualization\",\"interactive charts\",\"interactive data visualization\",\"interactive graphics\",\"interactive infographic\",\"interactive infographics\",\"interactive visualizations\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"javascript charting api\",\"JavaScript charting features\",\"JavaScript charting library\",\"javascript charts\",\"javascript drawing\",\"javascript drawing library\",\"javascript graph\",\"javascript graphics\",\"JavaScript graphics library\",\"JavaScript library\",\"JavaScript mapping library\",\"js chart\",\"js charting\",\"js charts\",\"JS graphics\",\"Marimekko chart\",\"mekko chart\",\"Mekko graphics\",\"mosaic chart\",\"Mosaic Plot\",\"part-to-whole relationships\",\"Pew Research\",\"Pew Research Center\",\"plotting\",\"social media adoption\",\"social media use\",\"Social Vulnerability Index\",\"statistic\",\"statistics\",\"statistics visualization\",\"storytelling examples\",\"survey\",\"survey data\",\"survey data visualization\",\"Tips and tricks\",\"top data visualization tools\",\"tutorial\",\"united states\",\"visual analysis\",\"visual analytics\",\"visual storytelling examples\",\"visualization\",\"web design\",\"web developers\",\"web development\",\"website\",\"website development\"],\"articleSection\":[\"AnyChart Charting Component\",\"HTML5\",\"JavaScript\",\"JavaScript Chart Tutorials\",\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/\",\"name\":\"Mosaic Plot: Learn How to Create It for Web with JavaScript (HTML5)\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot.png\",\"datePublished\":\"2022-08-15T11:36:17+00:00\",\"dateModified\":\"2022-09-08T14:44:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"See what a mosaic plot is, and learn how to create this chart with JavaScript for a web page or app, in this detailed, yet simple data viz tutorial.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot.png\",\"width\":1400,\"height\":787},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Mosaic Plot with JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\",\"url\":\"https:\/\/www.anychart.com\/blog\/\",\"name\":\"AnyChart News\",\"description\":\"AnyChart JS Charts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.anychart.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/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":"Mosaic Plot: Learn How to Create It for Web with JavaScript (HTML5)","description":"See what a mosaic plot is, and learn how to create this chart with JavaScript for a web page or app, in this detailed, yet simple data viz tutorial.","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\/08\/15\/mosaic-plot\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Mosaic Plot for Web with JavaScript","og_description":"See what a mosaic plot is and learn how to create one with JavaScript for any web page or app.","og_url":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2022-08-15T11:36:17+00:00","article_modified_time":"2022-09-08T14:44:53+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-social.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"How to Create Mosaic Plot for Web with JavaScript","twitter_description":"See what a mosaic plot is and learn how to create one with JavaScript for any web page or app.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot-social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"How to Create Mosaic Plot with JavaScript","datePublished":"2022-08-15T11:36:17+00:00","dateModified":"2022-09-08T14:44:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/"},"wordCount":1324,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot.png","keywords":["advanced data visualization","analysis","analytics","AnyChart","api","app development","best BI tools","best data visualization examples","best data visualization tool","best data visualization tools","BI tools","big data tools","chart design","chart development","chart examples","charting","charts","data","data analysis","data analytics","data analytics examples","data API","data chart","data charting","data charts","data comparison","data composition","data design","data graphic","data graphics","data journalism","data science","data visual","data visualisation","Data Visualization","data visualization best practices","data visualization design","data visualization development","data visualization examples","data visualization practice","data visualization tool","data visualization tutorial","data visualization weekly","data visualizations","data visuals","data viz examples","data-viz","dataviz","dataviz examples","dataviz weekly","drawing tools","example","front-end development","HTML","HTML charts","HTML5","html5 charts","infographic","infographics","information graphics","information visualization","interactive charts","interactive data visualization","interactive graphics","interactive infographic","interactive infographics","interactive visualizations","JavaScript","javascript chart tutorial","javascript charting","javascript charting api","JavaScript charting features","JavaScript charting library","javascript charts","javascript drawing","javascript drawing library","javascript graph","javascript graphics","JavaScript graphics library","JavaScript library","JavaScript mapping library","js chart","js charting","js charts","JS graphics","Marimekko chart","mekko chart","Mekko graphics","mosaic chart","Mosaic Plot","part-to-whole relationships","Pew Research","Pew Research Center","plotting","social media adoption","social media use","Social Vulnerability Index","statistic","statistics","statistics visualization","storytelling examples","survey","survey data","survey data visualization","Tips and tricks","top data visualization tools","tutorial","united states","visual analysis","visual analytics","visual storytelling examples","visualization","web design","web developers","web development","website","website development"],"articleSection":["AnyChart Charting Component","HTML5","JavaScript","JavaScript Chart Tutorials","Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/","url":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/","name":"Mosaic Plot: Learn How to Create It for Web with JavaScript (HTML5)","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot.png","datePublished":"2022-08-15T11:36:17+00:00","dateModified":"2022-09-08T14:44:53+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"See what a mosaic plot is, and learn how to create this chart with JavaScript for a web page or app, in this detailed, yet simple data viz tutorial.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/08\/mosaic-plot.png","width":1400,"height":787},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2022\/08\/15\/mosaic-plot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Mosaic Plot with JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.anychart.com\/blog\/#website","url":"https:\/\/www.anychart.com\/blog\/","name":"AnyChart News","description":"AnyChart JS Charts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.anychart.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/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\/15535","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=15535"}],"version-history":[{"count":17,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/15535\/revisions"}],"predecessor-version":[{"id":15646,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/15535\/revisions\/15646"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=15535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=15535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=15535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}