我试图通过向 svg 添加一个新圆圈来填充圆环图的中间。圆圈应该是白色的,覆盖背景中的水平线,但我在圆环图中间实现了透明圆圈。
这是我到目前为止的代码,img 在此处输入图像描述:
var width = 650,
height = 500,
outerRadius = 100,
innerRadius = outerRadius - 80;
var arc = d3.svg.arc()
.outerRadius(outerRadius)
.innerRadius(innerRadius);
var arcOver = d3.svg.arc()
.innerRadius(innerRadius)
.outerRadius(outerRadius + 5);
var pie = d3.layout.pie()
.sort(null)
.value(function(d) { return d.value; });
// Define the div for the tooltip
var div = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var svg = d3.select('.chart-container').append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(325,250)");
svg.append("svg:circle")
.attr("cx", 0)
.attr("cy", 0)
.attr("r", 20)
.append("g");
这应该可以解决问题:
svg.append("svg:circle")
.attr("cx", 0)
.attr("cy", 0)
.attr("r", 20)
.style("fill", "white")
.append("g");
或者,更好的方法是执行以下操作:
svg.append("svg:circle")
.attr("cx", 0)
.attr("cy", 0)
.attr("r", 20)
.attr("class", "white-circle")
.append("g");
然后,在 CSS 中:
.white-circle {
fill: #FFF;
}