chart = {
const chart = new G2.Chart({
width,
height: 1200,
paddingLeft: 50
});
chart.coordinate({ type: "transpose" });
chart
.interval()
.data(stateages)
.transform({ type: "normalizeY" })
.scale("color", { range: d3.schemeSpectral[ages.length] })
.scale("x", {
domain: d3.groupSort(
stateages,
(D) => -D[0].population / d3.sum(D, (d) => d.population),
(d) => d.state
)
})
.scale("y", {
tickCount: 20,
guide: { position: "top", formatter: d3.format(".0%") }
})
.encode("x", "state")
.encode("y", "population")
.encode("color", "age");
return node(chart.render());
}