Skip to content
Advertisement

Donut chart d3.js labels

I’m new to d3.js and I’m trying to change this code. What I actually need is to have each slice’s name on it. The problem is that labels need to change for each button. For example, if you click on culture/Media the labels are – German, English, History but for medicine are – Dentist, Pharmacist…

donut chart

any help is highly appreciated 🙂

JavaScript
JavaScript
JavaScript

Advertisement

Answer

I’ve refactored your code a bit, since you kept doing the same thing a lot. Look at the update function for that.

You also didn’t account for more/fewer slices depending on the selection, so I added that as well.

The texts do not animate yet, but I think you should be able to manage that.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement