Label outside arc (Pie chart) d3.js

后端 未结 8 1431
日久生厌
日久生厌 2020-11-28 03:55

I\'m new to d3.js and I\"m trying to make a Pie-chart with it. I have only one problem: I can\'t get my labels outside my arcs... The labels are positioned with arc.centroid

8条回答
  •  情书的邮戳
    2020-11-28 04:38

    yes baby, it's SOHCAHTOA

    function coordinates_on_circle(hyp, angle){
      var radian= angle * Math.PI / 180 //trig uses radians
      return {
        x: Math.cos(radian) * hyp, //adj = cos(r) * hyp
        y: Math.sin(radian) * hyp //opp = sin(r) * hyp
      }
    }
    var radius=100
    var angle=45
    coordinates_on_circle(radius, angle)

提交回复
热议问题