d3.js Map (<svg>) Auto Fit into Parent Container and Resize with Window

前端 未结 5 2210
时光取名叫无心
时光取名叫无心 2020-12-23 16:54

UPDATE: I have posted and accepted a fully working solution in the answers section. Any code in this section is to be used as reference for comparison to your own NO

5条回答
  •  爱一瞬间的悲伤
    2020-12-23 17:34

    The selection object is an multidimensional array, although in most cases it will probably have only one object in it. That object has a "clientWidth" field that tells you how wide its parent is.

    So you can do this:

    var selection = d3.select("#chart"); 
    width = selection[0][0].clientWidth;
    

提交回复
热议问题