barChart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg
.append("text")
.attr("x", width / 2)
.attr("y", 30)
.attr("text-anchor", "middle")
.style("font-size", "22px")
.style("text-decoration", "underline")
.text("Animal Crossing Villager Cats Personality Counts");
svg
.append("text")
.attr("x", width / 2)
.attr("y", height - 3)
.style("font-size", "16px")
.style("text-anchor", "middle")
.text("Personality");
svg
.append("text")
.attr("x", (height / 2) * -1)
.attr("y", margin.left - 27)
.style("text-anchor", "middle")
.style("font-size", "16px")
.attr("transform", "rotate(-90)")
.text("Count");
svg
.append("g")
.attr("class", "bars")
.attr("fill", "steelblue")
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", d => px(d.key))
.attr("y", d => py(d.value))
.attr("height", d => py(0) - py(d.value))
.attr("width", px.bandwidth());
svg
.append("g")
.attr("class", "x-axis")
.call(pxAxis)
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.style("font-size", "5px")
.style("text-anchor", "end");
svg
.append("g")
.attr("class", "y-axis")
.call(pyAxis);
return svg.node();
}