我有一个新问题。 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