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!
let scale = d3.scaleLinear().domain([1,10]).range([1, 300]);
var svg = d3.select("body").append("svg")
.attr("width", 360)
.attr("height", 500)
let render = (data, color) => {
let rects = svg.selectAll("rect").data(data);
rects.exit().remove();
rects.enter().append("rect")
.attr("y", 20)
.attr("x", scale)
.attr("width", 20)
.attr("height", 20)
.merge(rects)
.attr("fill", color)
}
render([1, 2, 2.5], "red");
render([1, 2, 3, 4, 5], "blue");
</script>
</body>
https://d3js.org/d3.v4.min.js