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("Calories by Cereal");
svg
.append("text")
.attr("x", width / 2)
.attr("y", height - 3)
.style("font-size", "16px")
.style("text-anchor", "middle")
.text("Cereal Name");
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("Calories");
svg
.append("g")
.attr("class", "bars")
.attr("fill", "steelblue")
.selectAll("rect")
.data(cereal)
.join("rect")
.attr("x", d => barX(d.name))
.attr("y", d => barY(d.cal))
.attr("height", d => barY(0) - barY(d.cal))
.attr("width", barX.bandwidth());
svg
.append("g")
.attr("class", "x-axis")
.call(barxAxis)
.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(baryAxis);
return svg.node();
}