D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
MettiHoof
Full window
Github gist
Circles_1
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; } </style> </head> <body> <script> //setup elements var circleData = [ { "cx": 20, "cy": 20, "radius": 20, "color" : "green" }, { "cx": 70, "cy": 70, "radius": 20, "color" : "purple" }]; var rectangleData = [ { "rx": 110, "ry": 110, "height": 30, "width": 30, "color" : "blue" }, { "rx": 160, "ry": 160, "height": 30, "width": 30, "color" : "red" }]; var svgContainer = d3.select("body").append("svg") .attr("width",300) .attr("height",300); // Append an SVG group element to the svg container var circleGroup = svgContainer.append("g"); //put the circles in the group and not in the svgContainer like done before var circles = circleGroup.selectAll("circle") .data(circleData) .enter() .append("circle"); var circleAttributes = circles .attr("cx", function (d) { return d.cx; }) .attr("cy", function (d) { return d.cy; }) .attr("r", function (d) { return d.radius; }) .style("fill", function (d) { return d.color; }); </script> </body>
https://d3js.org/d3.v4.min.js