D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
sampathweb
Full window
Github gist
merging selections
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> // Feel free to change or delete any of the code you see in this editor! var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500) var dataFirst = [ {ldap: "enjalot", x: 0}, {ldap: "siumei", x: 1}, {ldap: "ramesh", x: 2} ] var dataLater = [ {ldap: "sami", x: 3}, {ldap: "logan", x: 4}, {ldap: "phillip", x: 5}, {ldap: "siumei", x: 6} ]; svg.selectAll("circle") .data(dataFirst, function(d) { return d.ldap; }) .enter() .append("circle") .attr("r", 30) .attr("cx", function(d, i) { return 50 + i * 80 }) .attr("cy",100) .attr("fill", "#eda39a") .on("mouseover", function(d) { console.log(d); }) setTimeout(function() { var circles = svg.selectAll("circle") .data(dataLater, function(d){ return d.ldap; }); var enteredCircles = circles .enter() .append("circle") .attr("r", 30) .attr("cx", function(d, i) { return 50 + d.x * 80 }) .attr("cy",100) .attr("fill", "#862417"); enteredCircles.merge(circles) .attr("cx", function(d, i){ return 50 + d.x * 80 }) .style("stroke", "#111") }, 1000) </script> </body>
https://d3js.org/d3.v4.min.js