score:1

Accepted answer

id in HTML is unique, only 1 tag should have it.

Select the div for the bars, then selectAll tags with class is bar and bind data.

Remove the id you add to the rects.

var bars = d3.select("#scatter_versus_fatal_rect")
    .selectAll(".bar")
    .data(scatter_versus_dataset_filtered);

bars.enter()
    .append("rect")
    // .attr('id', 'scatter_versus_fatal_rect')
    .classed("bar", true)
    ......

Related Query

More Query from same tag