1
設置在創建中d3.js的對象,這是我經常的做法:d3.js與屬性的百分比,而不是像素
var svgcanvas = d3.select("body")
.append("svg")
.attr("width", 100)
.attr("height", 100)
.append("circle")
.attr("cx", 50)
.attr("cy", 50)
.attr("r", 10)
.attr("fill", "red")
它會在年底完全靜態的對象。我想要做的是有這樣的事情(注意百分比):
var svgcanvas = d3.select("#tweets")
.append("svg")
.attr("width", 100%)
.attr("height", 100%)
.append("circle")
.attr("cx", 50%)
.attr("cy", 50%)
.attr("r", 10)
.attr("fill", "red")
但它似乎不可能。
手動創建svg元素時,這樣做就像一個魅力。這裏是一個例子 http://cssdeck.com/labs/jxda8sth
對於這樣一個天真的解決方案,挖掘自動縮放腳本是一個禁忌我。所以我想問一下:是否可以用一個幾乎只有css的解決方案來完成它(如上面的解決方案)?
.attr( 「寬度」, 「100%」)?似乎沒有工作(腳本錯誤) – Mia 2014-10-08 10:33:08
jsfiddle在答案在Firefox上適合我。 – 2014-10-08 11:13:07