D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
greenmna
Full window
Github gist
Flag Question Final
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> var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500) var flag = [{"fill": "#FFFFFF", "x":250, "y": 150, "height": 75}, {"fill": "#C8102E", "x":250, "y": 225, "height": 75}, {"cx": 50, "cy": 50, "r": 50, "fill": "#C8102E"}]; console.log(flag); svg.selectAll() .data(flag) .enter() .append("rect") .attr("y", function (d) {return d.y}) .attr("x", function(d) {return d.x;}) .attr("width", 300) .attr("height", function (d){return d.height}) .attr("fill", function (d) {return d.fill;}) .attr("stroke", "black") .append("circle") .attr("cx", function (d) {return d.cx}) .attr("cy", function (d) {return d.cy}) .attr("r", function (d) {return d.r}) .attr("fill", function (d) {return d.fill}) </script> </body>
https://d3js.org/d3.v4.min.js