D3 shapes

In this example below you will see how to do a D3 shapes with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 13thDayCoder, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 13thDayCoder ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>D3 shapes</title>
  
  
  
  
  
</head>

<body>

  
  <script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/13thDayCoder/d3-shapes-GvxVWW */
var jsonCircles = [{ "x_axis": 30, "y_axis": 30, "radius": 20, "color": "green" }, { "x_axis": 70, "y_axis": 70, "radius": 20, "color": "purple" }, { "x_axis": 110, "y_axis": 100, "radius": 20, "color": "red" }];

var svgContainer = d3.select("body").append("svg");

var circles = svgContainer.selectAll("circle").data(jsonCircles).enter().append("circle");

var circleAttributes = circles.attr("cx", function (d, i) {
                          return i * 50 + 50;
}).attr("cy", function (d, i) {
                          return 50;
}).attr("r", function (d) {
                          return d.radius;
}).style("fill", function (d) {
                          return d.color;
});

Comments