我有一個新問題。 D3能否得出這個結論: http://www.nytimes.com/interactive/2008/05/03/business/20080403_SPENDING_GRAPHIC.html?_r=0 在d3中使用voronoi函數嗎?我在想的是一個svg,它的行爲像一個,並將這裏找到的voronoi http://bl.ocks.org/mbostock/4060366綁定到一個圓圈。紐約時報使用閃光燈完成了上述可視化。 任何想法? 我曾嘗試創建一個大圓圈並嵌入小圓圈,但voronoi不顯示,並且點不限於外圈。 代碼生成:d3可以在一個形狀內建立形狀嗎?
<svg class="PiYG" width="560" height="570">
<circle cx="270" cy="300" r="260" style="stroke: rgb(0, 0, 0);">
<g>
我的js代碼看起來像這樣:
var width = 560, height = 570;
var svg = d3.select("#VD1").append("svg")
.attr("width", width)
.attr("height", height)
.attr("class", "PiYG");
var path = svg.append("circle")
.attr("cx", 270)
.attr("cy", 300)
.attr("r", 260)
.style("stroke", "#000")
.append("g")
.selectAll("path");
var vertices = d3.range(count).map(function(d) {
return [Math.random() * width, Math.random() * height];
});
var voronoi = d3.geom.voronoi()
.clipExtent([[0, 0], [width, height]]);
svg.selectAll("circle")
.data(vertices.slice(2))
.enter().append("circle")
.attr("transform", function(d) { return "translate(" + d + ")"; })
.attr("r", 2);
非常感謝!
你所引用的是一個voronoi樹圖 - 對Michael Balzer和Oliver Deussen提出的標準矩形樹圖提供了一個相當不錯的改進。我目前正在研究如何使用d3完成這項工作,所以如果你成功了,請分享:) – ThomasP85
你有沒有想過這個?如果是這樣,你願意分享你的解決方案代碼嗎?我正在嘗試製作類似的可視化文件,並且無法使用d3來實現它。 – punkrockpolly