Remember the SVG we had at the beginning: This one is plain HTML:
But we can build the same also with D3: (look at the code)
The first thing was to put the d3-library file into our project folder and link it to our HTML:
<script src="./scripts/d3.min.js"></script>
Then we created an empty SVG with the id="d3svg", in which we will later bind the elements. After that we opened a script-tag to write Code into our HTML-file.With d3.select we selected the SVG we've created (The selection works in the same way as we learned it with CSS) and saved it into a variable. With .append() we added Child-Tags to it. And we can add attributes to these tags with .attr(). With this we have created exactly the same SVG as before. Only dynamically with D3, easy, isn't it?