我有一个小的D3脚本:
<script>
d3.csv("../data/school_attendance.csv", function(data) {
// Use d3.pie() to create and configure the data that we need in a format that we can enter into.
let arc_data = d3.pie().value(d => d['YTD Enrollment(Avg)']).padAngle(d => 0.0115)(data);
// Create the arc factory function that will render each data segment.
let arc = d3.arc().innerRadius(75).outerRadius(160);
// Run through each element of arc_data, creating and appening the arc for each one.
d3.select("svg")
.append("g")
.attr("id", "transform")
.attr("transform", "translate(400, 200)")
.selectAll('path')
.data(arc_data)
.enter()
.append('path')
.attr('d', arc)
.attr('fill', 'steelblue');
// Use arc and arc_data to calculate centroids, and from there to calculate.
arc_data.forEach(function(d, i) {
[x, y] = arc.centroid(d);
let label = d.data['District']
// let rotation = d['startAngle'] * 180 / Math.PI;
let rotation = d['startAngle'] / Math.PI / 2
d3.select("#transform").append("text")
.attr("x", x).attr("y", y)
.attr("text-anchor", "middle").attr("alignment-baseline", "middle")
.attr("transform", "rotate(" + rotation + ")")
.text(label);
})
})
</script>
这将产生以下输出:
![enter image description here](https://istack.dev59.com/yp1Bj.webp)
然而,对我来说显而易见的答案是:
let rotation = d['startAngle'] / Math.PI / 2 * 360 - 90;
预期效果未出现:
我在这里犯了什么错误,应该怎么修复?