Like every other element of a webpage, charts deserve to be responsive: their size must adapt to the device size. This post describes several approaches allowing to get this feature for d3.js charts.
A common pattern to make a chart responsive:
width
with this piece of code: parseInt(d3.select('#my_dataviz').style('width'), 10)
width
is createddiv
size changes
First of all, make sure you understood how this basic area chart is built with d3.js. The following example just uses the concept described above to make it responsive. Try to change the window size!
debouncing
The most common way to add responsiveness in d3.js is to use an event listener. Here is the basic idea:
Using the bootstrap grid as a workaround for responsiveness