D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
scresawn
Full window
Github gist
learning JSON
learning JSON
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> var spaceCircles = [30, 70, 110]; var svgContainer = d3.select("body").append("svg") .attr("width", 2000) .attr("height", 200); var circles = svgContainer.selectAll("circle") .data(spaceCircles) .enter() .append("circle"); var circleAttributes = circles .attr("cx", function (d) { return d; }) .attr("cy", function (d) { return d; }) .attr("r", 20 ) .style("fill", function(d) { var returnColor; if (d === 30) { returnColor = "green"; } else if (d === 70) { returnColor = "purple"; } else if (d === 110) { returnColor = "red"; } return returnColor; }); </script> </body>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js