how to create labels for data in donut chart using

2019-02-08 15:52发布

问题:

I have a donut chart which updates data on click. I want to add labels to the same data. I am currently using the d3.js javascript library. Here is my code on jsfiddle

What I don't understand it how to add labels to segments of the donut chart?

回答1:

You have to use the arc.centroid function. Take a look at the following examples:

  • http://jsfiddle.net/nrabinowitz/GQDUS/
  • http://bl.ocks.org/2295263
  • http://jsfiddle.net/MX7JC/9/
  • http://blog.stephenboak.com/2011/08/07/easy-as-a-pie.html


回答2:

Please take a look at: http://nvd3.org/examples/pie.html or http://bl.ocks.org/Guerino1/2295263. Check the code and you should be able to answer this question fairly easy. Have fun!