chart = {
const svg = d3
.create("svg")
.attr("width", chart_width)
.attr("height", chart_height)
.attr("viewBox", [0, 0, chart_width, chart_height]);
svg
.append("g")
.attr(
"transform",
`translate(0,${chart_height - margin.bottom - margin.top})`
)
.call(d3.axisBottom(x));
svg
.append("g")
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y));
svg
.selectAll(".rect")
.data(data)
.enter()
.append("rect")
.attr("x", margin.left)
.attr("y", (d) => y(d.country) + y_group(d.gender))
.attr("width", (d) => x(+d.n) - margin.left)
.attr("height", y.bandwidth() / 3)
.attr("fill", (d) => fill_scale(d.gender));
return svg.node();
}