chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("aria-roledescription", "chart");
svg.append("g")
.attr("fill", "steelblue")
.selectAll("rect")
.data(data)
.join("rect")
.attr("role", "progressbar")
.attr("aria-label", (d) => d.name)
.attr("aria-valuemin", 0)
.attr("aria-valuemax", 100)
.attr("tabindex", 0)
.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", "transparent")
.selectAll("text")
.data(data)
.join("text")
.text(d => d.name)
svg.append("g")
.attr("fill", "white")
.attr("text-anchor", "end")
.attr("font-family", "sans-serif")
.attr("font-size", 12)
.selectAll("text")
.data(data)
.join("text")
.attr("id", d => `label-${d.name}`)
.attr("x", d => x(d.value))
.attr("y", (d, i) => y(i) + y.bandwidth() / 2)
.attr("dy", "0.35em")
.attr("dx", -4)
.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"));
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis)
return svg.node();
}