0

I have donut chart. I want to make the edge of donut to be curvy as the image shows enter image description here. I tried to use this code to achieve what I want but I can't.

var arc = d3.svg.arc()
        .innerRadius(innerRadius)
        .outerRadius(outerRadius)
        .startAngle(0);
user3002180
  • 431
  • 6
  • 19

2 Answers2

3

You can use the cornerRadius property of d3.svg.arc(), added in D3 v3.5

var arc = d3.svg.arc()
    .innerRadius(innerRadius)
    .outerRadius(outerRadius)
    .cornerRadius(outerRadius - innerRadius)
    .startAngle(0);

http://jsfiddle.net/Lxnymj28/1/

Marjan
  • 1,378
  • 1
  • 14
  • 21
  • 3
    cornerRadius is a bit buggy, I don't know if that is because of d3 or just how SVGs work. It glitches out if you have an arc approaching 360 degrees or something like 1 degree. – Nikolay Dyankov Sep 22 '15 at 12:39
2

The d3.svg.arc() generator assumes you are giving it a single datum, not a list data. It therefore assumes that each of startAngle, endAngle, innerRadius, outerRadius is either a constant or a function of the single datum.

You cannot directly make the ends of the arc rounded over using this generator.

You could, however, draw two circles over the endpoints of the arc, using arc.centroid(startAngle) and arc.centroid(endAngle) as their centers and (outerRadius-innerRadius)/2 as their radius. This will give you the rounded-over appearance.

Documentation: arc.centroid

Timothy Shields
  • 75,459
  • 18
  • 120
  • 173