javascript 如何使用 d3.js 为圆环图中的数据创建标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12506819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to create labels for data in donut chart using d3.js
提问by Swaraj
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.jsjavascript library. Here is my code on jsfiddle
我有一个圆环图,它在点击时更新数据。我想为相同的数据添加标签。我目前正在使用d3.jsjavascript 库。 这是我在 jsfiddle 上的代码
What I don't understand it how to add labels to segments of the donut chart?
我不明白如何为圆环图的各个部分添加标签?
回答by zemirco
You have to use the arc.centroidfunction. Take a look at the following examples:
您必须使用arc.centroid函数。看看下面的例子:
回答by paxRoman
Please take a look at: http://nvd3.org/examples/pie.htmlor http://bl.ocks.org/Guerino1/2295263. Check the code and you should be able to answer this question fairly easy. Have fun!
请查看:http: //nvd3.org/examples/pie.html或http://bl.ocks.org/Guerino1/2295263。检查代码,您应该能够相当容易地回答这个问题。玩得开心!