score:0

Accepted answer

This can be resolved by changing the last line to:

.attr("fill", d => d3.color(colorr(d.InspectionScore))));

The reason this works is that d3's attr allows you to take the attribute value from a function. In this case you want to transform the data element to either red or blue. This is what the arrow function does in the above code. It is equivalent to :

.attr("fill", function(d) {
    return d3.color(colorr(d.InspectionScore));
    })

To get a deeper understanding of how D3 works, you can check the tutorials.


Related Query

More Query from same tag