A14 – Creating New Elements

The purpose of this assignment is to provide practice creating and adding new elements to the DOM using D3.


1. For this assignment create files named elements.html, elements.css, and elements.js.

2. In the elements.html file, create a svg element with an id attribute set to “barGraph”.   Use d3’s append method to create a bar graph that is similar to the one that you created in assignment 9.

3. In the elements.html file, create an svg element with an id attribute set to “pieChart”.  Use d3’s insert method to create a pie chart that is similar to the one that you created in assignment 9.

4. Clone the bar graph using d3’s clone method and insert it after the pie chart.  Change the color of the bars to red.

5. Create a button labeled “Remove” such that each time the button is pressed, the first bar in the second bar graph is removed using d3’s remove method.

 

 

 

© 2018 – 2021, Eric. All rights reserved.