chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg
.append("g")
.selectAll("g")
.data(series)
.join("g")
.attr("fill", (d, i) => barColours[i % 3])
.classed("bar-group",true)
.selectAll("rect")
.data(d => d)
.join("rect")
.attr("x", d => x(d[0]))
.attr("y", (d, i) => y(d.data["Police force"]))
.attr("width", d => x(d[1]) - x(d[0]))
.attr("height", y.bandwidth())
svg
.append("line")
.attr("x1", x(medianTotalCed))
.attr("y1", graph.margin.top + 2)
.attr("x2", x(medianTotalCed))
.attr("y2", height - graph.margin.bottom)
.style("stroke-width", 1)
.style("stroke-dasharray", ("1,2"))
.style("stroke", colours.secondary50)
.style("fill", "none")
svg
.append("text")
.attr("x", x(medianTotalCed) + 5)
.attr("y", height - graph.margin.bottom - 5)
.text("Average")
.attr("text-anchor", "start")
.attr("font-family", graph.font)
.attr("font-size", graph.fontSize)
.style("fill", colours.secondary)
svg
.append("g")
.attr("fill", colours.primary)
.attr("text-anchor", "start")
.attr("font-family", graph.font)
.attr("font-size", graph.fontSize)
.selectAll("text")
.data(series[1])
.join("text")
.attr("x", d => x(d[0]))
.attr("y", (d, i) => y(d.data['Police force']) + y.bandwidth() / 2)
.attr("dy", "0.35em")
.attr("dx", 5)
.text(d => d3.format(".1f")(d[0]))
svg
.append("g")
.attr("fill", colours.primary)
.attr("text-anchor", "start")
.attr("font-family", "sans-serif")
.attr("font-size", graph.fontSize)
.selectAll("text")
.data(series[1])
.join("text")
.attr("x", d => x(d[0]))
.attr("y", (d, i) => y(d.data['Police force']) + y.bandwidth() / 2)
.attr("dy", "0.35em")
.attr("dx", 5)
.text(d => d3.format(".1f")(d[0]))
svg
.append("g")
.attr("fill", colours.primary)
.attr("text-anchor", "start")
.attr("font-family", graph.font)
.attr("font-size", graph.fontSize)
.selectAll("text")
.data(ced_per_100_by_force.sort((a,b) => b.Total - a.Total))
.join("text")
.attr("x", d => x(d.Total))
.attr("y", (d, i) => y(d['Police force']) + y.bandwidth() / 2)
.attr("dy", "0.35em")
.attr("dx", 5)
.text(d => d3.format(".1f")(d.Total))
.call(text => text.filter(d => d.Total > 40)
.text(d => d3.format(".1f")(d.Total))
.attr("x", width - 10)
.attr("fill", "white")
.attr("text-anchor", "end"));
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
return svg.node()
}