简体   繁体   中英

d3 svg to fill screen

I am trying to get the d3 svg visualization on this page to fill the screen.

The HTML in my files is an empty div:

<div id='d3'>
</div>

When the page loads, it is populated with the following:

<svg width="1390" height="475"><g transform="translate(55,55)"> … </g></svg>

How can I tweak this width and height before hand to make it fill the page?

I'm very new to D3! So can't give more info..but I found this JQuery Answer which you could use to first get at the width then just plug it in.

https://stackoverflow.com/a/1038765/709872

Apparently without JQuery to help it's more complicated! Hope this points you in the right direction.

If you want to fill the screen with you svg maybe you can do this:

  var width = $(window).width();
  var height = $(window).height(); 

  var svgContainer = d3.select("#d3").append("svg")                                  
    .attr("width", width)
    .attr("height", height);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM