Charts help us to visualise data, but not only do different types of chart suit different types of data, the space available for them also affects the choice. Space is often at a premium in applications, particularly when viewed on mobile devices, plus any data must be understood quickly.

For sneak-peek or tiny charts that sit in-line with that data, such as rows on a table, bar or pie chart sparklines work particularly well. However, for a larger chart that sits in a responsive space — one that adapts its size to optimally fit the screen displaying it — such as a panel in a Bootstrap structure, I’ve recently favoured treemaps, powered by the brilliant d3 library. However, I couldn’t immediately find an example of a responsive version, using native HTML rather than SVG, but did find a simple solution myself.

This gave me a good excuse to try CodePen, so feel free to view my test example in action there. As you can see from the screenshots in the gallery of this article, a bar chart will happily fill expanding horizontal space, but it makes less sense to let it expand vertically, as the difference in the height of the bars wastes space. This might be fine, but if you want to use the entire area and make a big impact, especially on mobile, try the treemap.

Creating these small chart samples in CodePen with d3 was easy and fun, and having drawn more inspiration around the web, I’m just looking for the right excuses to build some more!