-1
我正在尝试使用d3构建基于饼图中数据总值的大小不同的饼图数组。我如何根据饼图总数改变饼图的大小?
有谁知道我怎么可能从D3例如采取HTML文件:
http://bl.ocks.org/mbostock/3888852
并修改饼图半径正比于从馅饼CSV文件中的总数据图表?
我正在尝试使用d3构建基于饼图中数据总值的大小不同的饼图数组。我如何根据饼图总数改变饼图的大小?
有谁知道我怎么可能从D3例如采取HTML文件:
http://bl.ocks.org/mbostock/3888852
并修改饼图半径正比于从馅饼CSV文件中的总数据图表?
这里有一个快速的尝试:
...
data.forEach(function(d) {
d.total = 0;
d.ages = color.domain().map(function(name) {
d.total += +d[name]; // add a total of all population for each state
return {name: name, population: +d[name]};
});
});
// determine the maximum population for all states (ie California)
var maxPopulation = d3.max(data, function(d){
return d.total;
});
// now for each d.age (where the the arcs come from)
// stash an arc function based on a scaled size
data.forEach(function(d) {
var r = radius * (d.total/maxPopulation);
var someArc = d3.svg.arc() // make the radius scale according to our max population
.outerRadius(r)
.innerRadius(r - (r-10));
d.ages.forEach(function(a){
a.arc = someArc; // stash the arc in the d.ages data so we can access later
})
});
...
svg.selectAll(".arc")
.data(function(d) { return pie(d.ages); })
.enter().append("path")
.attr("class", "arc")
.attr("d", function(d){
return d.data.arc(d); // use our stashed arc function to create the path arc
})
.style("fill", function(d) { return color(d.data.name); })
例here。
你可能不得不改变我如何缩放派的大小。我的线性方法很有效,但与CA相比,一些州的人数很少,他们的饼图可查看。