Built with blockbuilder.org
xxxxxxxxxx
<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 margin = {left: 40, right: 40, top: 40, bottom: 40};
var width = 800 - margin.left - margin.right;
var height = 400 - margin.top - margin.bottom;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
var data = [
[20, 40, 80, 100, 80, 70, 25],
[20, 30, 40],
[100, 90, 10, 20]
];
var colorScale = d3.scaleOrdinal(d3.schemeCategory10);
function updateBars(data) {
var rectWidth = 40;
var rects = svg.selectAll('rect')
.data(data);
rects.exit().remove();
var enter = rects.enter()
.append('rect')
.attr('width', rectWidth)
.attr('stroke', 'white');
rects = enter.merge(rects)
.attr('x', function(d, i) { return (i * rectWidth) + margin.left})
.attr('y', function(d) { return (height - d) })
.attr('height', function(d) { return d})
.attr('fill', function(d) { return colorScale(d)})
.on('click', function(d) { console.log(d)});
}
var index = 0;
setInterval(function() {
updateBars(data[index % 3]);
index++;
}, 2000);
</script>
</body>
https://d3js.org/d3.v4.min.js