D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
leorawe
Full window
Github gist
Rectangles Update Function
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> <svg width="960" height="500"></svg> <script> var t = d3.transition() .duration(500) function render(data){ var rects = d3.select("svg") .selectAll("rect") .data(data) rects .exit() .style("fill","red") // .transition().duration(1000) .remove() rects .enter() .append("rect") .attr("x",function(d){return d;}) .attr("y", 100) .attr("width", 70) .attr("height",300) .style("fill","green") .merge(rects) .attr("x",function(d){return d;}) } render([100, 300]); render([100, 200, 400]); //render([100, 400]); render([300]); render([100, 200, 300,400]); </script> </body>
https://d3js.org/d3.v4.min.js