D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
lindep
Full window
Github gist
Add_elements_by_function
Built with
blockbuilder.org
<!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; } svg { width:100%; height: 100% } </style> </head> <body> <script> var x = 10, y = 30, width = 600, height = 480; function drawCircles(svg, data) { var circles = svg.selectAll('circle').data(data); circles.enter().append('circle') .attr('r', 3); circles.exit().remove(); circles .attr('cx', function(d) { return d.x }) .attr('cy', function(d) { return d.y }); } numPoints =272; var data = []; for (var i = 0; i < numPoints; i++) { data.push({ x: Math.random() * (width-3) + (x), y: Math.random() * (height-1) + (y) }); } var svg = d3.selectAll('svg').data([0]); svg.enter().append("svg"); svg.append("rect") .attr({x: x, y: y, width: width, height: height}) .style({ fill: "#a72d1a"}) .transition().duration(3000).ease("bounce") .style({ fill: "#5db9e3"}) drawCircles(svg, data); console.log(data); </script> </body>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js