答案 0 :(得分:1)
由于您确认将有4组数据
4个具有不同内径和外径的弧。
var biggestarc = d3.svg.arc()
.outerRadius(radius - 80)
.innerRadius(radius - 10);
var bigarc = d3.svg.arc()
.outerRadius(radius - 30)
.innerRadius(radius - 60);
var smallarc = d3.svg.arc()
.outerRadius(radius - 40)
.innerRadius(radius - 50);
var biggerarc = d3.svg.arc()
.outerRadius(radius - 20)
.innerRadius(radius - 70);
数据将采用此格式。
data = [{
"label": "Biggest",
"percent": 25 //percent to be shown for Biggest arc
}, {
"label": "Bigger",
"percent": 10 //percent to be shown for Bigger arc
}, {
"label": "Big",
"percent": 65 //percent to be shown for Big arc
}, {
"label": "Small",
"percent": 30 //percent to be shown for Small arc
}]
根据标签选择路径弧:
g.append("path")
.attr("d", function (d) {
console.log(d)
if (d.data.label == "Biggest") {
return biggestarc(d);
} else if (d.data.label == "Bigger") {
return biggerarc(d);
} else if (d.data.label == "Big") {
return bigarc(d);
} else {
console.log("target")
return smallarc(d);
}
})
工作代码here
希望这有帮助!