D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
jbelmont
Full window
Github gist
Enter and Append Circles
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } svg { width: 100%; height: 100%; } </style> </head> <body> <script> var myData = [1,2,3,4,5]; var svgViewport = d3.select("body") .append("svg") .attr("width","560") .attr("height","900"); // Update var circleSelection = svgViewport.selectAll("circle").data(myData); // Enter and Append var circleElements = circleSelection.enter().append("circle"); // Set properties for each circle circleElements .attr("cx",function(d,i) { return d * 50; }) .attr("cy",function(d,i) { return d * 50; }) .attr("r","25"); function colorCircles(d,i) { return i % 2 === 0 ? 'green' : 'red'; } // Style each circle var circleStyle = circleElements.style("fill", colorCircles); </script> </body>
https://d3js.org/d3.v4.min.js