This way the SVG image auto-adopts to 100% of the width.
// Adds the svg canvas to the selector - 'body' by default
var svg = d3.select(chart.selector())
.append('svg')
- .attr('width', width + margin.left + margin.right)
- .attr('height', height + margin.top + margin.bottom)
+ .attr("viewBox", "0 0 " + (width + margin.left + margin.right) + " " + (height + margin.top + margin.bottom))
+ .attr("preserveAspectRatio", "xMidYMid meet")
.append('g')
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');