score:2

Accepted answer

You need to set the viewbox attribute first. Try this:

var svg = d3.select("#chart").append("svg")
    .attr("viewBox", "0 0 " + (width) + " " + (height))
    .attr("preserveAspectRatio", "xMinYMin");

For this to work, you have to change your html:

<div id="chart"></div>

Related Query

More Query from same tag