chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg.append("g").call(yAxis);
svg
.append("g")
.selectAll("rect")
.data(data)
.join("rect")
.attr("stroke", (d, i) => colorStroke(i))
.attr("stroke-width", 2)
.attr("fill", (d, i) => color(i))
.attr("x", x(0))
.attr("y", (d, i) => y(i))
.attr("width", d => x(d.value) - x(0))
.attr("height", y.bandwidth());
svg
.append("g")
.attr("fill", "#333")
.attr("font-family", "sans-serif")
.attr("font-size", 18)
.attr("font-weight", "bold")
.selectAll("text")
.data(data)
.join("text")
.attr("x", d => x(d.value))
.attr("y", (d, i) => y(i) + y.bandwidth() / 2)
.attr("dy", "0.35em")
.attr("dx", 8)
.text(d => format(d.value))
.call(text =>
text
.filter(d => x(d.value) - x(0) < 20)
.attr("dx", +4)
.attr("fill", "black")
.attr("text-anchor", "start")
);
return svg.node();
}