D3.js 如何根据饼图总计改变饼图的大小?
我试图使用d3构建一个饼图数组,该数组的大小根据饼图中数据的总值而变化 有人知道我如何从d3示例中获取html文件吗:D3.js 如何根据饼图总计改变饼图的大小?,d3.js,D3.js,我试图使用d3构建一个饼图数组,该数组的大小根据饼图中数据的总值而变化 有人知道我如何从d3示例中获取html文件吗: 并修改饼图半径,使其与该饼图的csv文件中的数据总量成比例?下面是一个快速尝试: ... data.forEach(function(d) { d.total = 0; d.ages = color.domain().map(function(name) { d.total += +d[name]; // add a total of all p
并修改饼图半径,使其与该饼图的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); })
例如
你可能需要改变我如何缩放馅饼的大小。我的线性方法是可行的,但是一些州的人与CA相比太少,以至于他们的饼图是可以查看的