gpt4 book ai didi

javascript - D3 弧 - 不可见

转载 作者:行者123 更新时间:2023-11-30 15:40:22 29 4
gpt4 key购买 nike

我正在尝试实现多级饼图

我的初始代码在这里:JSFIDDLE

var departments = [
{
"name": "Sales",
"color": "green",
"count": 5
},
{
"name": "Tech Lead",
"color": "red",
"count": 8
},
{
"name": "HR",
"color": "orange",
"count": 3
},
{
"name": "Development",
"color": "blue",
"count": 12
},
{
"name": "QA",
"color": "pink",
"count": 6
},
{
"name": "Finance",
"color": "purple",
"count": 9
},
{
"name": "PL",
"color": "gray",
"count": 1
},
{
"name": "Marketing",
"color": "yellow",
"count": 4
}
];

var innerRadius = 50;
var outerRadius = 200;
var maxLeaveCount = departments.reduce(function(max, department) {
return (max < department.count) ? department.count : max;
}, 0);

var svgContainer = d3.select("#container").append("svg")
.attr("width", 3 * outerRadius)
.attr("height", 3 * outerRadius);


var arc = d3.svg.arc()
.innerRadius(innerRadius)
.outerRadius(function(d) {
(d.count / maxLeaveCount) * (outerRadius / 0.9)
})
.startAngle(function(d, i) {
return (2 * Math.PI * i) / departments.length;
})
.endAngle(function(d, i) {
return (2 * Math.PI * i) / departments.length + (2 * Math.PI) / departments.length;
})

svgContainer
.selectAll("path")
.data(departments)
.enter()
.append("svg:path")
.attr("d", arc)
.attr("transform", "translate(" + (3 * outerRadius) / 2 + "," + (3 * outerRadius) / 2 + ")")
.style("fill", function(d) {
return d.color;
})

但它什么也不渲染。有经验的人可以帮我把这个渲染出来吗?

最佳答案

您在 outerRadius 函数中缺少 return 语句

.outerRadius(function(d) {
return (d.count / maxLeaveCount) * (outerRadius / 0.9)
})

关于javascript - D3 弧 - 不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40918832/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com