svg - D3.js:饼图,仅向外部区域添加边框

标签 svg d3.js pie-chart

我在 D3 中得到了一个饼图,并用笔画分隔了每个切片。但是,我想仅向切片的外部区域添加边框,而不是在连续线上添加边框,而是尊重原始切片中的笔划创建的间隙。请参阅我的图片以进行澄清。关于如何做到这一点有什么想法吗?

参见http://jsfiddle.net/4xk58/

arcs.append("path")
.attr("fill", function (d, i) {
return color(i);
})
.attr("d", arc).style('stroke', 'white')
.style('stroke-width', 5);

I want an outter border like this

最佳答案

我通过添加两个额外的拱形组来解决这个问题,总共三个。 第一个是普通的馅饼,没有笔划

arcs.append("path")
.attr("fill", function (d, i) {
   return color(i);
}).attr("d", arc);

第二个是我想首先添加的边框。它只是围绕我们原来的拱门的一组拱门,但颜色不同。还没有中风。

最后,第三个架构将是真正绘制我想要的笔画的架构

//Draw phantom arc paths
phantomArcs.append("path")
  .attr("fill", 'white')
  .attr("fill-opacity", 0.1)
  .attr("d", arcPhantom).style('stroke', 'white')
  .style('stroke-width', 5);

这弥补了效果,参见 http://jsfiddle.net/odiseo/4xk58/4/

Desired visual effect

关于svg - D3.js:饼图,仅向外部区域添加边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20253129/

相关文章:

javascript - 避免使用 svg 图像进行光栅化,以便在 Firefox 中进行转换

css - 为什么我的 SVG 调用不起作用?

svg - 如何使用 Itext 7 将 SVG 添加到 PDF?

javascript - 获取 TypeError : . selectAll(...).enter 不是 d3.js 的函数

javascript - 在 div HTML 中定位多个 SVG 元素

d3.js - d3 轴方向 : center

javascript - 用ES6绘制饼图

android - Mp 饼图大小增加

python - 如何在 Python 3.4 中使用 dict_values 生成饼图?

javascript - 将 SVG 路径纵向分割为多种颜色