chart5 = {
const width = 500, height = 320;
const margin = { top: 40, right: 20, bottom: 50, left: 50 };
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const x = d3.scaleLinear()
.domain(d3.extent(fareBins.flatMap(d => [d.x0, d.x1])))
.nice()
.range([margin.left, width - margin.right]);
const y = d3.scaleLinear()
.domain([0, d3.max(fareBins, d => d.length)])
.nice()
.range([height - margin.bottom, margin.top]);
svg.append("g")
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(10).tickFormat(d => `$${d.toFixed(0)}`));
svg.append("g")
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y));
svg.append("text")
.attr("x", width / 2)
.attr("y", height - 10)
.attr("text-anchor", "middle")
.attr("font-size", "12px")
.text("Fare Paid (USD)");
svg.append("text")
.attr("x", -height / 2)
.attr("y", 15)
.attr("transform", "rotate(-90)")
.attr("text-anchor", "middle")
.attr("font-size", "12px")
.text("Number of Survivors");
svg.append("text")
.attr("x", width / 2)
.attr("y", margin.top / 2)
.attr("text-anchor", "middle")
.attr("font-size", "14px")
.attr("font-weight", "bold")
.text("Distribution of Fares Paid by Survivors");
svg.selectAll("rect")
.data(fareBins)
.join("rect")
.attr("x", d => x(d.x0))
.attr("y", d => y(d.length))
.attr("width", d => x(d.x1) - x(d.x0) - 1)
.attr("height", d => y(0) - y(d.length))
.attr("fill", "mediumseagreen");
return svg.node();
}