chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const rect = svg.selectAll("g")
.data(y01z)
.join("g")
.selectAll("rect")
.data(d => d)
.join("rect")
.attr("fill", (d, i) => z(d, i))
.attr("stroke", "grey")
.attr("x", (d, i) => x(i))
.attr("y", height - margin.bottom)
.attr("width", x.bandwidth())
.attr("height", 0);
svg.append("g")
.call(xAxis);
function transitionStacked() {
y.domain([0, y1Max]);
rect.transition()
.duration(500)
.delay((d, i) => i * 20)
.attr("y", d => y(d[1]))
.attr("height", d => y(d[0]) - y(d[1]))
.transition()
.attr("x", (d, i) => x(i))
.attr("width", x.bandwidth());
}
function update() {
transitionStacked();
}
return Object.assign(svg.node(), {update});
}