Built with blockbuilder.org
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body {
margin-left:15px;
position:fixed;
top:0;right:0;bottom:0;left:0;
margin-top:15px;
}
.enter {
fill: green;
}
.update {
fill: red;
}
.exit {
fill: brown;
}
</style>
</head>
<body>
<script>
// Feel free to change or delete any of the code you see in this editor!
var scale = d3.scaleLinear().domain([1, 10]).range([0, 300]); // Pixel space
var svg = d3.select("body").append("svg").attr("width", 350).attr("height", 250);
function render(data){
var t = d3.transition()
.duration(750);
var rects = svg.selectAll("rect").data(data, d => d);
rects.enter()
.append("rect")
.attr("class", "enter")
.attr('x', scale)
.attr("y", 60)
.attr("width", 20)
.attr("height", 20)
.style("fill-opacity", 1e-6)
.transition(t)
.attr("y", 0)
.style("fill-opacity", 1)
rects
.attr("class", "update")
.style("fill-opacity", 1)
.transition(t);
rects.exit()
.attr("class", "exit")
.transition(t)
.attr("y", 60)
.style("fill-opacity", 1e-6)
.remove();
}
let range = (num) => {
return new Array(num).fill(0).map((_, id) => id + 1);
}
d3.interval(() => {
render(range(Math.floor(Math.random() * 10) + 1));
}, 1000);
</script>
</body>
https://d3js.org/d3.v4.min.js