act_chart = {
const svg = d3.create("svg").attr("viewBox", [-50, 0, width, height + 100]);
svg.append("g").call(yAxis2);
svg.append("g").call(xAxis2);
svg
.selectAll('rect')
.data(act_data)
.join(enter => enter.append('rect'))
.attr('x', d => xScale2(d.x))
.attr('y', d => yScale2(minY2))
.attr('width', xScale2.bandwidth())
.attr('height', d => 0)
.transition()
.duration(1000)
.style("fill", "steelblue")
.attr("y", d => yScale2(d.y) + 15)
.attr("height", d => yScale2(minY2) - yScale2(d.y));
svg
.append("text")
.attr("class", "x label")
.attr("text-anchor", "middle")
.attr("x", width / 2)
.attr("y", height + 60)
.text("Sex And Ethnicity");
svg
.append("text")
.attr("class", "y label")
.attr("text-anchor", "end")
.attr("x", -height / 2)
.attr("y", 6)
.attr("transform", "rotate(-90)")
.text("Average Score");
svg
.append("text")
.text("Average ACT Score For Different Sex And Ethnicity")
.style("text-anchor", "middle")
.attr("transform", `translate(${width / 2}, 100)`)
.style("font-size", "1.2em");
const tooltip = svg.append("g");
svg
.selectAll('rect')
.on("mouseover", function(d) {
tooltip.call(
callout,
`${d.x}
Average Score: ${d.y}`
);
d3.select(this)
.attr("stroke", "black")
.attr("stroke-width", 2);
})
.on("mousemove", function() {
tooltip.attr(
"transform",
`translate(${d3.mouse(this)[0]},${d3.mouse(this)[1]})`
);
d3.select(this).style("fill", "orange");
})
.on("mouseout", function() {
tooltip.call(callout, null);
d3.select(this)
.attr("stroke", null)
.style("fill", "steelblue");
});
return svg.node();
return svg.node();
}