How to make force layout graph in D3.js responsive to screen/browser size

The problem is not within .size(), it’s that you are stating the SVG dimensions in .attr("width", w) .attr("height", h). Remove these two attributes and you’ll get it right…

var svg = d3.select("#viz").append("svg")
            .attr("id", "playgraph")
             //better to keep the viewBox dimensions with variables
            .attr("viewBox", "0 0 " + w + " " + h )
            .attr("preserveAspectRatio", "xMidYMid meet");

http://jsfiddle.net/aaSjd/

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)