Skip to content
Advertisement

How to create a pie chart visualization in d3.js, typing the input manually and with smooth transitions

I am trying to use D3.js to create a pie chart with 3 pie slices. I would like to input the values with the keyboard and the transition when updating the values (when clicking the button) should be smooth, that’s why I use merge() and transition().

In oder words, what I am trying to do is to adapt the code from this given example: https://www.d3-graph-gallery.com/graph/pie_changeData.html

the difference would be that I would like to be able to input the values manually instead of having them in the code (it is fine that it is always 3 pie slices).

For some reason I cannot really adapt the code. Thanks in advance.

JavaScript
JavaScript

Advertisement

Answer

To access the values in the input boxes, use this.value, not this.innerHtml, where this points to the relevant DOM node:

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