0
D3餅圖innerRadius和outerRadius作用時髦
餅圖弧每個似乎都有自己的半徑行爲,當我他們想要的所有份額,在通過了最高值的半徑。是相關的代碼。
var pie = d3.layout.pie()
.value(function(d) {
return d;
}).sort(null);
var arc = d3.svg.arc()
.innerRadius(function(d, i) { console.log(d, i); return (d.value * .6) })
.outerRadius(function(d) { return d.value; });
var fill = d3.scale.linear()
.domain([0, 2])
.range(["red", "blue"]);
var force = d3.layout.force()
.nodes(data)
.size([width + 250, height + 50])
.on("tick", tick)
.charge(charge)
.gravity(.15);
force.start();
function charge(d) {
return d.rank * d.rank * -.25;
}
var svg = d3.select("body").append("svg")
.attr("width", width + 250)
.attr("height", height + 50);
var nodes = svg.selectAll(".node")
.data(data)
.enter()
.append("g")
.attr("class", "node");
// .attr("cx", function(d) { return d.x; })
// .attr("cy", function(d) { return d.y; })
// .attr("r", function(d) { return d.rank; })
nodes.selectAll("path")
.data(function(d) {
var ar = [];
ar.push(prostitution_scale(d.prostitution));
ar.push(cigarette_scale(d.cigarettes));
ar.push(alcohol_scale(d.alcohol));
return pie(ar);
})
.enter()
.append("svg:path")
.attr("d", arc)
.style("fill", function(d, i) { return fill(i); })
.style("stroke", function(d, i) { return d3.rgb(fill(d.value)).darker(2); })
.call(force.drag);
抱歉,我應該提到的是我不想要的東西不變,我希望他們都設爲比例爲數組IM傳遞最大的價值。我將不得不爲每個一個或一個新弧??? – natecraft1
讓我更新問題,看看我是否正確理解你想要的。 –
我想你明白我想要什麼,但我試過了,它不工作。 = /。應該是segments.forEach而不是餡餅? (這也不工作)錯誤:問題解析d =「MNaN,NaNAundefined,undefined 0 1,1 NaN,NaNL0,0Z」 – natecraft1