{"id":19336,"date":"2020-03-16T10:56:10","date_gmt":"2020-03-16T10:56:10","guid":{"rendered":"http:\/\/www.highcharts.com\/blog\/?p=19336"},"modified":"2026-01-12T11:39:15","modified_gmt":"2026-01-12T11:39:15","slug":"interactive-infographics","status":"publish","type":"post","link":"https:\/\/www.highcharts.com\/blog\/tutorials\/interactive-infographics\/","title":{"rendered":"Interactive infographics"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Infographics, when done right, break out of the box of a \u201cstandard\u201d chart to tell a data-story in a more visually engaging way.<\/p>\n<p>Ironically, in this day and age, most infographics are static images. But, if you want to engage an online audience, why not use an interactive infographic?<\/p>\n<p>In this tutorial, I will show you how to build an interactive infographic with Highcharts.\u00a0The subject of this infographic is a comparison of Copa America and UEFA Euro 2016.; the numbers adapted from a \u201cstandard,\u201d static infographic found <a href=\"https:\/\/www.statista.com\/chart\/4959\/how-the-copa-america-and-euro-2016-measure-up\/\">here<\/a>.<\/p>\n<p>Feel free to check the<em><strong> <a href=\"http:\/\/marketing-demo.s3-website-eu-west-1.amazonaws.com\/\"><u>live version<\/u><\/a><\/strong><\/em>.<br \/>\n<a href=\"http:\/\/marketing-demo.s3-website-eu-west-1.amazonaws.com\/\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19371 aligncenter\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/16103053\/infographic-live-demo.jpg\" alt=\"\" width=\"523\" height=\"310\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/16103053\/infographic-live-demo.jpg 523w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/16103053\/infographic-live-demo-360x213.jpg 360w\" sizes=\"auto, (max-width: 523px) 100vw, 523px\" \/><\/a><\/p>\n<p>Our interactive infographic is a single page application (SPA). I built it without using any framework so that the code would be easy to deconstruct.<\/p>\n<p><i><b>Remark<\/b><br \/>\nBasic knowledge of Javascript, Node.js, expressJS, and MongoDB is highly recommended to understand the application code.<\/i><\/p>\n<p>I\u2019ll walk through the architecture first; then I will explain the code.<\/p>\n<h2>The architecture<\/h2>\n<p>Basically, the project is to combine a static and dynamic data set in order to create a more engaging infographic. The data are:<\/p>\n<ol>\n<li>The key numbers of Copa America &amp; Euro 2016.<\/li>\n<li>The result of a live quiz.<\/li>\n<\/ol>\n<p>The key numbers are stored within the project files, whereas the quiz results are saved into a database (MongoDB) then read via a server to be visualized.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19341 aligncenter\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13140717\/image2-1.jpg\" alt=\"\" width=\"624\" height=\"301\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13140717\/image2-1.jpg 624w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13140717\/image2-1-560x270.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13140717\/image2-1-360x174.jpg 360w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><br \/>\nLet\u2019s examine each part of the architecture.<\/p>\n<h2>Database<\/h2>\n<p>The quiz results are saved in MongoDB. There are two quizzes in this application:<\/p>\n<ol>\n<li>The first quiz is about the host for the 2016 Copa America and Euro 2016.<\/li>\n<li>The second quiz is about the most valuable player in each event.<\/li>\n<\/ol>\n<p><i><b>Remark<\/b><br \/>\nMongoDB is easy to use when building JavaScript apps, as it stores JSON natively. You are, of course, free to use any other database or service that suits you.<\/i><\/p>\n<p>Here is the structure of the data saved in the database:<br \/>\n<b>1.First quiz<\/b><\/p>\n<pre>{\r\n    \"name\": \"hostPolls\",\r\n    \"answers\": [\r\n        96,\r\n        44,\r\n        49,\r\n        49\r\n    ]\r\n}<\/pre>\n<p><b>2.Second quiz<\/b><\/p>\n<pre>{\r\n    \"name\": \"playerPolls\",\r\n    \"answers\": [\r\n        32,\r\n        9,\r\n        2,\r\n        27,\r\n        6,\r\n        9\r\n    ]\r\n}<\/pre>\n<h2>User interface<\/h2>\n<p>The user interface is pretty simple and straightforward; it has 13 pages (or screens, as it is a single page application). Each page displays either:<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>One main key number about both events.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19342\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141252\/image1-1.jpg\" alt=\"\" width=\"421\" height=\"250\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141252\/image1-1.jpg 729w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141252\/image1-1-560x333.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141252\/image1-1-360x214.jpg 360w\" sizes=\"auto, (max-width: 421px) 100vw, 421px\" \/><\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>A quiz.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19343\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141315\/image4.jpg\" alt=\"\" width=\"358\" height=\"374\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141315\/image4.jpg 393w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141315\/image4-268x280.jpg 268w\" sizes=\"auto, (max-width: 358px) 100vw, 358px\" \/><\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>The result of a quiz.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19344\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141334\/image6.jpg\" alt=\"\" width=\"424\" height=\"213\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141334\/image6.jpg 762w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141334\/image6-560x281.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141334\/image6-760x381.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141334\/image6-360x180.jpg 360w\" sizes=\"auto, (max-width: 424px) 100vw, 424px\" \/><\/p>\n<p>All the pages have two buttons to go to the next or previous page.<\/p>\n<p>The pages are under this folder <code>src\/pages<\/code>:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19349\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141550\/image3.jpg\" alt=\"\" width=\"754\" height=\"232\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141550\/image3.jpg 769w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141550\/image3-560x173.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141550\/image3-760x234.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/03\/13141550\/image3-360x111.jpg 360w\" sizes=\"auto, (max-width: 754px) 100vw, 754px\" \/><\/p>\n<p>To better organize the pages and to make the maintenance in the future easier, each page has its own folder, where one file has the data and the content of the visualization, and the other file has the HTML code.<\/p>\n<p>For example, the host page folder has the following files:<\/p>\n<ul>\n<li><code>host.js<\/code> has both event\u2019s maps where all the tournaments accrued.<\/li>\n<li><code>hostPage.js<\/code> has the HTML code to render the page.<\/li>\n<\/ul>\n<p>I use jQuery to perform an Ajax request to the server. Nevertheless, any other library or framework will work fine as well. The files related to managing the requests are under the folder utils.<\/p>\n<p>There are two requests <code>postPoll<\/code> and <code>getPoll<\/code>:<\/p>\n<pre>import ajax from '.\/ajax.js';\r\nexport function postPoll(route, answers) {\r\n  return ajax('POST', route, JSON.stringify(answers));\r\n}\r\nexport function getPoll(route) {\r\n  return ajax('GET', route);\r\n}<\/pre>\n<p>The ajax method is in the <code>ajax.js<\/code> file:<\/p>\n<pre>$.ajax({\r\n      type: type,\r\n      url: url + route,\r\n      dataType: 'json',\r\n      data: data,\r\n      contentType: 'application\/json',\r\n      success: function(result) {\r\n        resolve(result);\r\n      },\r\n      error: function(error) {\r\n        reject(error);\r\n      }\r\n    });<\/pre>\n<h2>Server<\/h2>\n<p>The main tasks of the server are to save the quiz data and to retrieve them from the database.<br \/>\nI built the server using Node.js, with the following modules :<\/p>\n<ul>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/express\">Express<\/a> to create the local server.<\/li>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/request\">Request<\/a> to communicate with the user interface.<\/li>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/mongoose\">Mongoose<\/a> to manage the mongo database.<\/li>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/config-json\">Config-js<\/a> to store logins and passwords of the database.<\/li>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/cors\">Cors<\/a> to avoid cross-origin policy issues, to learn more about the policy, click <a href=\"https:\/\/en.wikipedia.org\/wiki\/Same-origin_policy\">here<\/a>.<\/li>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/path\">Path<\/a> to deal with file paths in a portable way (note that this module is a part of node itself).<\/li>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/clear\">Clear<\/a> to launch the clear screen command before each session.<\/li>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/aws-serverless-express\">AWS Serverless Express<\/a> to run the serverless application on top of AWS lambda and Amazon API Gateway.<\/li>\n<\/ul>\n<p><i><b>Remark<\/b><br \/>\nBe sure to protect your credentials by using a <code>config.json<\/code> file<\/i><\/p>\n<pre>{\r\n    \"dbCredentials\":{\r\n        \"DBlogin\" : \"myLogin\",\r\n        \"DBpwd\" : \"letMeIn\" \r\n    },\r\n    \"BLink\" : \"myLinkTo\/infographic\"                \r\n}<\/pre>\n<p>The server offers four routes:<\/p>\n<ul>\n<li><code>postHostData<\/code> to save the host quiz answers into the database.<\/li>\n<li><code>getHostData<\/code> to read the host quiz result from the database.<\/li>\n<li><code>postPlayerData<\/code> to save the player quiz answers into the database.<\/li>\n<li><code>getPlayerData<\/code> to read the player quiz result from the database.<\/li>\n<\/ul>\n<p>Once all the components of the application are created, all you have to do is to find a web service to host the application. I use the online cloud web service AmazonAWS, but any other service can do the job. Notice the file <code>lambda.js<\/code> to run the application on AWS lambda.<br \/>\nThe code of this file is very basic:<\/p>\n<pre>const awsServerlessExpress = require('aws-serverless-express');\r\nconst app = require('.\/lib\/app');\r\nconst server = awsServerlessExpress.createServer(app);\r\nexports.handler = (event, context) =&gt; {\r\n  return awsServerlessExpress.proxy(server, event, context);\r\n};<\/pre>\n<p>Well, that\u2019s it, it is that easy. Now you know how to build a responsive interactive infographic with the library Highcharts, and all that without a framework.<\/p>\n<p>Feel free to share your experience with infographics and Highcharts, and let me know if you have any questions or remarks using the comments section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Step by step tutorial to build an interactive infographic with Highcharts as a single page application.<\/p>\n","protected":false},"author":32,"featured_media":19376,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"meta_title":"","meta_description":"","hc_selected_options":[],"footnotes":""},"categories":[210],"tags":[1094,876],"coauthors":[699],"class_list":["post-19336","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-highcharts-core","tag-highcharts-maps"],"_links":{"self":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/19336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/comments?post=19336"}],"version-history":[{"count":1,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/19336\/revisions"}],"predecessor-version":[{"id":29228,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/19336\/revisions\/29228"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media\/19376"}],"wp:attachment":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media?parent=19336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/categories?post=19336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/tags?post=19336"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/coauthors?post=19336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}