{"id":12038,"date":"2021-01-25T08:51:22","date_gmt":"2021-01-25T08:51:22","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=12038"},"modified":"2022-09-17T14:33:06","modified_gmt":"2022-09-17T14:33:06","slug":"bubble-map-javascript","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/","title":{"rendered":"How to Create Bubble Map with JavaScript to Visualize Election Results"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone size-full wp-image-12051\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5.png\" alt=\"Bubble Map created with JavaScript visualizing election results\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5.png 1100w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5-300x196.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5-768x503.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5-1024x670.png 1024w\" sizes=\"(max-width: 1100px) 100vw, 1100px\" \/>In these times of exponentially growing data, visualization is a necessary skillset to have in your tool box. Popular techniques include bar charts, line graphs, pie charts, and bubble maps among others.<\/p>\n<p>Building interactive charts from scratch with JavaScript can be a difficult endeavor for any developer, especially someone starting out new. That is exactly why we have <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">JS charting libraries<\/a> which make it much easier and quicker to conjure up insightful visualizations!<\/p>\n<p>Read on to see how I create a JavaScript Bubble Map with one of these libraries.<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>JavaScript Charting Libraries<\/h2>\n<p>There are quite a few great JavaScript libraries available to use and each one of them has its own pros and cons. But the best part is that the process of building charts with all of them is mostly similar. So, you can learn the ropes with any one and then use whichever library suits your requirement for a particular project.<\/p>\n<p>I have decided to use <a href=\"https:\/\/www.anychart.com\/\">AnyChart JavaScript Library<\/a> for creating bubble maps along with this tutorial. I think it is a great choice for developers with novice to intermediate level of coding skills. AnyChart is flexible with extensive documentation and has a variety of chart types to kick start your visualization journey.<\/p>\n<h2>What Is Bubble Map and What Will It Show?<\/h2>\n<p>I know you are excited to start creating the visualization but before we begin, it is important to understand the chart type and why it is a good fit for what we want to show.<\/p>\n<p>A bubble map is essentially a combination of a bubble chart and a map where the bubbles are plotted over geographical regions. The size of the bubble indicates the value of the particular variable, with the position on the map indicating location.<\/p>\n<p>One of the most important events of 2020 was the US presidential election. Of course, we know the overall outcome. But wouldn\u2019t it be interesting to see who won in which states and by what percentage \u2014 all in just one view? I certainly think so! While I&#8217;m sure many of us have seen a lot of 2020 US election maps, I will create my own and show you how, step by step!<\/p>\n<p>I am going to use the bubble map chart where I will plot the bubbles over each American state. The 3 indicated parameters will be as follows:<\/p>\n<ol>\n<li>The number of electoral votes for each state, by the bubble size.<\/li>\n<li>The winning party for each state, by the bubble color.<\/li>\n<li>Percentage of votes won, by the color opacity.<\/li>\n<\/ol>\n<p>As you can see, the superpower of a bubble map chart is the ability to show multiple parameters in a single viz.<\/p>\n<h2>Creating Bubble Map with JavaScript<\/h2>\n<p>Now that you know what a bubble map is and hoping that you are convinced about it being the right chart to represent state-wise results of the US Elections, let&#8217;s dive into the process.<\/p>\n<h3>1. Create a basic HTML page<\/h3>\n<p>The initial step is to create a blank HTML page. To hold my chart, I add a div element with a unique id that I will use to reference it later.<\/p>\n<p>I set the width and height of the placeholder div to 100% so that the chart is displayed over the entire screen. You can keep these values as per your preference.<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n\u00a0\u00a0&lt;title&gt;Bubble Map&lt;\/title&gt;\r\n\u00a0\u00a0&lt;style&gt;\r\n\u00a0\u00a0\u00a0\u00a0html,\r\n\u00a0\u00a0\u00a0\u00a0body,\r\n\u00a0\u00a0\u00a0\u00a0#container {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0height: 100%;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0margin: 0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0padding: 0;\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>2. Include the necessary script<\/h3>\n<p>The next step is to link the appropriate JS scripts that will be used to create the bubble map. Since I am using the AnyChart library, I will reference the corresponding files. For my chart, I need to add AnyChart\u2019s Base and Geo Maps <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules\" target=\"_blank\" rel=\"nofollow\">modules<\/a>. I also need to include the file that has the geodata for the US states which is also available in the library\u2019s <a href=\"https:\/\/cdn.anychart.com\/\" target=\"_blank\" rel=\"nofollow\">CDN<\/a>.<\/p>\n<p>Just to remind you, all the script files need to be included in the <code>&lt;head&gt;<\/code> section of the HTML page.<\/p>\n<pre><code class=\"html\">&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.9.0\/js\/anychart-base.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.9.0\/js\/anychart-map.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.9.0\/geodata\/countries\/united_states_of_america\/united_states_of_america.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\n<h3>3. Connect the data<\/h3>\n<p>There are a ton of datasets available for the US election results. For this chart, we need specific fields so I had to create the final dataset by combining data from multiple sources. I used the dataset about the number of electoral votes per state from <a href=\"https:\/\/www.loc.gov\/resource\/g3701f.cp000001\/?r=-0.147%2C-0.028%2C1.412%2C0.867%2C0\" target=\"_blank\" rel=\"nofollow\">The Library of Congress<\/a> site and the winner data from <a href=\"https:\/\/www.google.com\/search?q=us%20election%20results&amp;oq=us%20election%20results&amp;aqs=chrome.0.69i59j0l4j69i60j69i61j69i60.2463j0j7&amp;sourceid=chrome&amp;ie=UTF-8\" target=\"_blank\" rel=\"nofollow\">The Associated Press<\/a>.<\/p>\n<p>The AnyChart library supports many data formats, including CSV, JSON, XML&#8230; To make things simpler here, I have pre-processed the data to include relevant fields for our chart which are as follows:<\/p>\n<ol>\n<li>State code<\/li>\n<li>Latitude<\/li>\n<li>Longitude<\/li>\n<li>State name<\/li>\n<li>Number of electoral votes<\/li>\n<li>Winning party<\/li>\n<li>% of votes won<\/li>\n<\/ol>\n<p>You can download the JSON file <a href=\"https:\/\/gist.githubusercontent.com\/shacheeswadia\/70ec3d69e0e7a8bff7917607ea2926e4\/raw\/c3329fa81e86d9e637503b042becd17e68d9a718\/bubbleMapData.json\" target=\"_blank\" rel=\"nofollow\">here<\/a>.<\/p>\n<p>Before we start using the data, we will need to include 2 more script files to our HTML page. The <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Data_Adapter\/Overview\" target=\"_blank\" rel=\"nofollow\">Data Adapter<\/a> module handles the loading of the data file, so we include that. Since we are creating a map, we will make use of another JavaScript library \u2014 Proj4js \u2014 which transforms point coordinates from one coordinate system to another. In simple terms, it will take care of plotting the bubbles over the respective geographical areas.<\/p>\n<h3>4. Add the code to draw the chart<\/h3>\n<p>Now that the preliminaries are over, it is time to get to the main part. The great part about using JavaScript charting libraries is that the amount of code one has to write can be really small. I will walk you through the lines of code so that you have a better understanding of how the bubble map is drawn.<\/p>\n<p>Firstly, I will make sure that all the code for creating the chart is inside the <code>anychart.onDocumentReady()<\/code> function. This is to have the page fully loaded before anything else is executed. Next we load the data using <code>anychart.data.loadJsonFile()<\/code> function.<\/p>\n<p>I create the map first, define some settings for it, and set the geodata. I also add a title to the map.<\/p>\n<pre><code class=\"javascript\">anychart.onDocumentReady(function () {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.data.loadJsonFile(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'https:\/\/gist.githubusercontent.com\/shacheeswadia\/70ec3d69e0e7a8bff7917607ea2926e4\/raw\/c3329fa81e86d9e637503b042becd17e68d9a718\/bubbleMapData.json',\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0function (data) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Creates map chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var map = anychart.map();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Define settings for maps regions\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0map\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.unboundRegions()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.enabled(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.fill('#E1E1E1')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.stroke('#D2D2D2');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Set geodata using the script added\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0map.geoData('anychart.maps.united_states_of_america');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Set Chart Title\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0map\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.title('2020 US Election Results');\r\n           \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});<\/code><\/pre>\n<p>Next, I will add the bubbles over the map. Since tiny bubbles would not be visible well and very large bubbles would create a messy overlap, I set a minimum and maximum bubble size.<\/p>\n<pre><code class=\"javascript\">\/\/ Set bubble min\/max size settings\r\nmap.minBubbleSize('0.8%').maxBubbleSize('5%');<\/code><\/pre>\n<p>Now, since we want to show the election results, we need to indicate the winner for each state by the winning party color \u2014 blue for Democrats and red for Republicans. For this we check the winner in the data and assign the fill attribute with the corresponding color.<\/p>\n<pre><code class=\"javascript\">\/\/ Fill color based on the winner\r\ndata.forEach(function(d){\r\n  if(d.winner == \"Democrats\"){\r\n    d.fill = \"#019bd8\";\r\n  }else{\r\n    d.fill = \"#d81c28\";\r\n  }\r\n});<\/code><\/pre>\n<p>I then plot the bubbles according to the data and set the size of the bubble to reflect the number of electoral votes from the data. I enable the default tooltip and labels for the bubble chart with a bit of styling.<\/p>\n<p>The final steps are setting the container to reference the previously added HTML block element and drawing the chart.<\/p>\n<p>That\u2019s it \u2014 a beautiful, fully functional, interactive bubble map is ready with just these few lines of HTML and JS code!<\/p>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-UUvc1rJR\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/XXi0CMJD\/iframe\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-UUvc1rJR{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p>You can check out this initial version on <a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/MWjvdbG\" target=\"_blank\" rel=\"nofollow\">CodePen<\/a>\u00a0[or on <a href=\"https:\/\/playground.anychart.com\/kMJRXssK\" target=\"_blank\" rel=\"nofollow\">Playground<\/a>]. For your convenience, here is the complete code:<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.9.0\/js\/anychart-base.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.9.0\/js\/anychart-map.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.9.0\/geodata\/countries\/united_states_of_america\/united_states_of_america.js\"&gt;&lt;\/script&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.9.0\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/proj4js\/2.3.15\/proj4.js\"&gt;&lt;\/script&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0body,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#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    \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;body&gt;\r\n    \r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;script&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.onDocumentReady(function () {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.data.loadJsonFile(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'https:\/\/gist.githubusercontent.com\/shacheeswadia\/70ec3d69e0e7a8bff7917607ea2926e4\/raw\/c3329fa81e86d9e637503b042becd17e68d9a718\/bubbleMapData.json',\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0function (data) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Creates map chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var map = anychart.map();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Define settings for maps regions\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0map\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.unboundRegions()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.enabled(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.fill('#E1E1E1')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.stroke('#D2D2D2');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Set geodata using the script added\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0map.geoData('anychart.maps.united_states_of_america');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Set Chart Title\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0map\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.title('2020 US Election Results');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Set bubble min\/max size settings\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0map.minBubbleSize('0.8%').maxBubbleSize('5%');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Fill color based on the winner\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0data.forEach(function(d){\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if(d.winner == \"Democrats\"){\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0d.fill = \"#019bd8\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}else{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0d.fill = \"#d81c28\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/Charting the bubbles\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var series = map.bubble(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.data.set(data).mapAs({ size: 'electoralvotes' })\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Tooltip\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0series\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.tooltip(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.stroke('2 #E1E1E1')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.fill('#1976d2')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.selectionMode('none');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Labels\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0series\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.labels()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.enabled(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.anchor('left-center')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.position('right')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.fontSize(11)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.offsetX(5);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Set container id for the chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0map.container('container');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Initiates chart drawing\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0map.draw();\r\n            \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n    \r\n\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Customizing Bubble Map<\/h2>\n<p>JS charting libraries usually provide a range of pre-built customization options.<\/p>\n<p>The existing bubble map is already great but we can tweak it with just a bit of more code and make it more insightful, aesthetically better and improve the information shown.<\/p>\n<h3>A. Assign opacity based on the winning vote percentage<\/h3>\n<p>It is always a good idea to showcase maximum information in one view without adding too much complexity. So I want to add one more aspect to the visualization by representing the percentage of votes won with the opacity of the bubble color, and it will be a great opportunity to show you how it is possible to involve a different JavaScript library in the process if you need some certain functionality from it.<\/p>\n<p>I will take <a href=\"https:\/\/d3js.org\/\" target=\"_blank\" rel=\"nofollow\">D3.js<\/a>, a famous open source JS library for data graphics, and use it to create a linear scale that would accept the value of the percentage of the votes from data and return the corresponding opacity value. For this, I add the required D3 scripts and then add the code to make the scale. I adjust the input and output values according to the data. Lastly, I add the opacity value to the fill attribute.<\/p>\n<pre><code class=\"javascript\">\/\/ Linear scale to get opacity values\r\nvar opacity = d3.scaleLinear()\r\n              .domain([49, 70])\r\n              .range([0.4, 0.9]);\r\n\r\n\/\/ Fill color based on winner and opacity based on % of votes won\r\ndata.forEach(function(d){\r\n  var opacityVal = opacity(d.votepercent);\r\n  opacityVal = opacityVal.toFixed(2);\r\n  if(d.winner == \"Democrats\"){\r\n    d.fill = \"#019bd8 \" + opacityVal;\r\n  }else{\r\n    d.fill = \"#d81c28 \" + opacityVal;\r\n  }\r\n});<\/code><\/pre>\n<p>Don\u2019t get overwhelmed if you don\u2019t fully understand this part. It is slightly beyond the beginner level but still can be helpful to many and it\u2019s not too complicated, you see.<\/p>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-NK1qJRV1\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/vcxhhdzC\/iframe\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-NK1qJRV1{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p><a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/zYKEqKm\" target=\"_blank\" rel=\"nofollow\">View on CodePen<\/a><br \/>\n[<a href=\"https:\/\/playground.anychart.com\/vcxhhdzC\" target=\"_blank\" rel=\"nofollow\">View on Playground<\/a>]<\/p>\n<h3>B. Improve the tooltip<\/h3>\n<p>The default tooltip just shows the state name with its latitude\/longitude and value that corresponds to the number of electoral votes for each state.<\/p>\n<p>We can customize the tooltip to display the information that we want to show \u2014 something bit more meaningful.<\/p>\n<p>For each state, I decided to show the winning party name, the number of electoral votes and the percentage of votes won by the winner. Since I want to show multiple fields, I enable HTML for the tooltip that would allow me to format the text. I then add all the information in HTML format and modify some styling. Ah, now the tooltip feels like a constructive supplement to the bubble map visualization.<\/p>\n<pre><code>\/\/ Enable HTML for labels\r\nseries.tooltip().useHtml(true);\r\n\r\n\/\/ Customize tooltip text\r\n\u00a0\u00a0series\r\n\u00a0\u00a0\u00a0\u00a0.tooltip()\r\n\u00a0\u00a0\u00a0\u00a0.titleFormat(\"&lt;h6 style='font-size:16px;margin: 0.2rem 0; font-weight:400;'&gt;{%name}\")\r\n\u00a0\u00a0\u00a0\u00a0.format(\"&lt;h6 style='font-size:14px; font-weight:400; margin: 0.2rem 0;'&gt;Winning Party: &lt;b&gt;{%winner}&lt;\/b&gt;&lt;\/h6&gt;&lt;h6 style='font-size:14px; font-weight:400; margin: 0.2rem 0;'&gt;Electoral Votes: &lt;b&gt;{%electoralvotes}&lt;\/b&gt;&lt;\/h6&gt;&lt;h6 style='font-size:14px; font-weight:400; margin: 0.2rem 0;'&gt;% of votes won: &lt;b&gt;{%votepercent}%&lt;\/b&gt;&lt;\/h6&gt;\");<\/code><\/pre>\n<h3>C. Enhancing the overall appearance of the chart<\/h3>\n<p>Just some last, simple modifications to enhance the chart. I add a subtitle for the chart with some styling and change the label colors to give it a bit more contrast.<\/p>\n<p>One last thing I adjust is the color of the bubbles when hovered over them.<\/p>\n<p>Voila! We have an enthralling and effective, JavaScript based bubble map visualization to showcase the US election results data by state!<\/p>\n<p><iframe sandbox=\"allow-scripts allow-pointer-lock allow-same-origin\n                 allow-popups allow-modals allow-forms\" frameBorder=\"0\" class=\"anychart-embed anychart-embed-GMYiX13C\"\n        allowtransparency=\"true\" allowfullscreen=\"true\"\n        src=\"https:\/\/playground.anychart.com\/kMJRXssK\/iframe\"><br \/>\n<\/iframe><br \/>\n<script type=\"text\/javascript\">(function(){\nfunction ac_add_to_head(el){\n\tvar head = document.getElementsByTagName('head')[0];\n\thead.insertBefore(el,head.firstChild);\n}\nfunction ac_add_style(css){\n\tvar ac_style = document.createElement('style');\n\tif (ac_style.styleSheet) ac_style.styleSheet.cssText = css;\n\telse ac_style.appendChild(document.createTextNode(css));\n\tac_add_to_head(ac_style);\n}\nac_add_style(\".anychart-embed-GMYiX13C{width:100%;height:600px;}\");\n})();<\/script><\/p>\n<p><a href=\"https:\/\/codepen.io\/shacheeswadia\/pen\/wvzrGrd\" target=\"_blank\" rel=\"nofollow\">View on CodePen<\/a><br \/>\n[<a href=\"https:\/\/playground.anychart.com\/kMJRXssK\" target=\"_blank\" rel=\"nofollow\">View on Playground<\/a>]<\/p>\n<h2>Conclusion<\/h2>\n<p>As you see, it is easy and exciting to create interactive data visualizations like bubble maps using a JavaScript library. You can look into other <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_JavaScript_charting_libraries\" target=\"_blank\" rel=\"nofollow\">JavaScript charting libraries<\/a> and find out more about each of them.<\/p>\n<p>I hope this tutorial has gotten you interested in data visualization and made you excited to start exploring JavaScript charts. Please feel free to ask any questions, offer suggestions or drop a comment. All in all, don\u2019t wait to start creating beautiful, useful visualizations!<\/p>\n<hr \/>\n<p><em>Published with permission of Shachee Swadia. Originally appeared on <a href=\"https:\/\/hackernoon.com\/how-to-create-a-bubble-map-with-javascript-to-visualize-election-results-lb213155\" target=\"_blank\" rel=\"nofollow\">Hacker Noon<\/a> under the title &#8220;How to Create a Bubble Map with JavaScript to Visualize Election Results: A beginner level tutorial to get started with data visualization by creating an interesting and intuitive JS bubble map&#8221; on December 30, 2020.<\/em><\/p>\n<hr \/>\n<p><em>Check out other <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a>.<\/em><\/p>\n<p><em>If you want to write a compelling guest post for our blog <a href=\"https:\/\/www.anychart.com\/support\/\">get in touch<\/a>.<\/em><\/p>\n<p><!-- SyntaxHighlighter --><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/default.min.css\"><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/atom-one-light.min.css\"><script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/highlight.min.js\"><\/script><script>hljs.initHighlightingOnLoad();<\/script><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>In these times of exponentially growing data, visualization is a necessary skillset to have in your tool box. Popular techniques include bar charts, line graphs, pie charts, and bubble maps among others. Building interactive charts from scratch with JavaScript can be a difficult endeavor for any developer, especially someone starting out new. That is exactly [&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,66,263,22,23,13,279,4],"tags":[2165,980,53,92,235,1740,284,127,258,44,2242,282,471,266,620,1293,2171,2220,54,1760,256,1111,744,844,165,1370,328,1544,458,2155,421,2150,2164,1762,1025,32,55,150,809,36,907,141,81,57,67,147,58,65,56,68,1937,1938,1728,340,237,502,459,30,172,309,1090,293,745,899,1939,1407,335],"class_list":["post-12038","post","type-post","status-publish","format-standard","hentry","category-anychart-charting-component","category-anymap","category-big-data","category-charts-and-art","category-html5","category-javascript","category-javascript-chart-tutorials","category-tips-and-tricks","tag-2020-election-results","tag-2020-u-s-presidential-election","tag-anychart","tag-anymap","tag-bubble-map","tag-bubble-maps","tag-chart-examples","tag-chart-types","tag-charts","tag-charts-and-art","tag-d3","tag-data","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-map","tag-data-vis","tag-data-visual","tag-data-visualization","tag-data-visualization-design","tag-data-visualization-examples","tag-data-visualization-practice","tag-data-visualization-techniques","tag-data-visualization-tutorial","tag-data-visualizations","tag-data-viz-examples","tag-election","tag-election-data","tag-election-data-visualization","tag-election-results","tag-elections","tag-electoral-college","tag-electoral-maps","tag-guest-post","tag-hacker-noon","tag-html5","tag-html5-charts","tag-html5-maps","tag-interactive-maps","tag-javascript","tag-javascript-chart-tutorial","tag-javascript-charting","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-map","tag-javascript-maps","tag-js-chart","tag-js-charting","tag-js-charts","tag-js-maps","tag-json","tag-json-data-visualization","tag-map","tag-map-visualizations","tag-maps","tag-politics","tag-statistics","tag-tips-and-tricks","tag-tutorial","tag-united-states","tag-us-maps","tag-visualization","tag-visualization-techniques","tag-visualizations","tag-visualizing-json-data","tag-vote","tag-voting","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Building Bubble Map with JavaScript to Visualize Election Results<\/title>\n<meta name=\"description\" content=\"Wondering how to create an interactive bubble map with JavaScript? Learn from this beginner-level tutorial. Visualizing U.S. election data for illustration.\" \/>\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\/2021\/01\/25\/bubble-map-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building Bubble Map with JavaScript to Visualize Election Results\" \/>\n<meta property=\"og:description\" content=\"Wondering how to create an interactive bubble map with JavaScript? Learn from this beginner-level tutorial. Visualizing U.S. election data for illustration.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/\" \/>\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=\"2021-01-25T08:51:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-17T14:33:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5-social.png\" \/>\n<meta name=\"author\" content=\"Shachee Swadia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Building Bubble Map with JavaScript to Visualize Election Results\" \/>\n<meta name=\"twitter:description\" content=\"Wondering how to create an interactive bubble map with JavaScript? Learn from this beginner-level tutorial. Visualizing U.S. election data for illustration.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5-social-1.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\/2021\/01\/25\/bubble-map-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"How to Create Bubble Map with JavaScript to Visualize Election Results\",\"datePublished\":\"2021-01-25T08:51:22+00:00\",\"dateModified\":\"2022-09-17T14:33:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/\"},\"wordCount\":1751,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5.png\",\"keywords\":[\"2020 election results\",\"2020 U.S. Presidential election\",\"AnyChart\",\"AnyMap\",\"bubble map\",\"bubble maps\",\"chart examples\",\"chart types\",\"charts\",\"Charts and Art\",\"D3\",\"data\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data map\",\"data vis\",\"data visual\",\"Data Visualization\",\"data visualization design\",\"data visualization examples\",\"data visualization practice\",\"data visualization techniques\",\"data visualization tutorial\",\"data visualizations\",\"data viz examples\",\"election\",\"election data\",\"election data visualization\",\"election results\",\"elections\",\"Electoral College\",\"electoral maps\",\"guest post\",\"Hacker Noon\",\"HTML5\",\"html5 charts\",\"html5 maps\",\"interactive maps\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"JavaScript charting library\",\"javascript charts\",\"javascript map\",\"javascript maps\",\"js chart\",\"js charting\",\"js charts\",\"js maps\",\"JSON\",\"JSON data visualization\",\"map\",\"map visualizations\",\"maps\",\"politics\",\"statistics\",\"Tips and tricks\",\"tutorial\",\"united states\",\"US maps\",\"visualization\",\"visualization techniques\",\"visualizations\",\"visualizing JSON data\",\"vote\",\"voting\"],\"articleSection\":[\"AnyChart Charting Component\",\"AnyMap\",\"Big Data\",\"Charts and Art\",\"HTML5\",\"JavaScript\",\"JavaScript Chart Tutorials\",\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/\",\"name\":\"Building Bubble Map with JavaScript to Visualize Election Results\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5.png\",\"datePublished\":\"2021-01-25T08:51:22+00:00\",\"dateModified\":\"2022-09-17T14:33:06+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"Wondering how to create an interactive bubble map with JavaScript? Learn from this beginner-level tutorial. Visualizing U.S. election data for illustration.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5.png\",\"width\":1100,\"height\":720},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Bubble Map with JavaScript to Visualize Election Results\"}]},{\"@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":"Building Bubble Map with JavaScript to Visualize Election Results","description":"Wondering how to create an interactive bubble map with JavaScript? Learn from this beginner-level tutorial. Visualizing U.S. election data for illustration.","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\/2021\/01\/25\/bubble-map-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Building Bubble Map with JavaScript to Visualize Election Results","og_description":"Wondering how to create an interactive bubble map with JavaScript? Learn from this beginner-level tutorial. Visualizing U.S. election data for illustration.","og_url":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2021-01-25T08:51:22+00:00","article_modified_time":"2022-09-17T14:33:06+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5-social.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"Building Bubble Map with JavaScript to Visualize Election Results","twitter_description":"Wondering how to create an interactive bubble map with JavaScript? Learn from this beginner-level tutorial. Visualizing U.S. election data for illustration.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5-social-1.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\/2021\/01\/25\/bubble-map-javascript\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"How to Create Bubble Map with JavaScript to Visualize Election Results","datePublished":"2021-01-25T08:51:22+00:00","dateModified":"2022-09-17T14:33:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/"},"wordCount":1751,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5.png","keywords":["2020 election results","2020 U.S. Presidential election","AnyChart","AnyMap","bubble map","bubble maps","chart examples","chart types","charts","Charts and Art","D3","data","data analysis","data analytics","data analytics examples","data map","data vis","data visual","Data Visualization","data visualization design","data visualization examples","data visualization practice","data visualization techniques","data visualization tutorial","data visualizations","data viz examples","election","election data","election data visualization","election results","elections","Electoral College","electoral maps","guest post","Hacker Noon","HTML5","html5 charts","html5 maps","interactive maps","JavaScript","javascript chart tutorial","javascript charting","JavaScript charting library","javascript charts","javascript map","javascript maps","js chart","js charting","js charts","js maps","JSON","JSON data visualization","map","map visualizations","maps","politics","statistics","Tips and tricks","tutorial","united states","US maps","visualization","visualization techniques","visualizations","visualizing JSON data","vote","voting"],"articleSection":["AnyChart Charting Component","AnyMap","Big Data","Charts and Art","HTML5","JavaScript","JavaScript Chart Tutorials","Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/","url":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/","name":"Building Bubble Map with JavaScript to Visualize Election Results","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5.png","datePublished":"2021-01-25T08:51:22+00:00","dateModified":"2022-09-17T14:33:06+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"Wondering how to create an interactive bubble map with JavaScript? Learn from this beginner-level tutorial. Visualizing U.S. election data for illustration.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2021\/01\/bubble-map-javascript-html5.png","width":1100,"height":720},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2021\/01\/25\/bubble-map-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Bubble Map with JavaScript to Visualize Election Results"}]},{"@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\/12038","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=12038"}],"version-history":[{"count":22,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/12038\/revisions"}],"predecessor-version":[{"id":15714,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/12038\/revisions\/15714"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=12038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=12038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=12038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}