简体   繁体   English

在d3动态饼图上添加动态标签

[英]Add dynamic label on d3 dynamic pie chart

I use D3.js to create a dynamic pie chart. 我使用D3.js创建动态饼图。 I want the user can chose what informations he wants to display. 我希望用户可以选择他要显示的信息。 So I want labels can appears an disappears. 所以我希望标签可以出现消失。 (for the moment it's random choice but in future the user can chose particular part of the pie) (目前是随机选择,但将来用户可以选择派的特定部分)

I want to display "age" value on the pie (show this JsFiddle ). 我想在饼图上显示“年龄”值(显示此JsFiddle )。

If I tried to append text or create "g" group it doesn't works, the pie chart doesn't stay dynamics ... I think I must use var g = svg.selectAll("path").enter().append("g") somewhere to create group and add text label and path in, but I fail to understand how to do that. 如果我试图添加文本或创建“ g”组不起作用,则饼图不会保持动态……我想我必须使用var g = svg.selectAll("path").enter().append("g")某处创建组并在其中添加文本标签和路径,但是我不明白该怎么做。

Sorry for my poor english 对不起,我英语不好

Thanks for your help 谢谢你的帮助

You weren't adding the text element back into the chart on change. 您没有在更改时将text元素添加回图表中。 I've fixed this here . 我已经把这个固定在这里了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM