Using d3-legend to create an legend from an ordinal scale, but with a sequential color scheme. I chose this method because the categorical values imply order, as they represent values that have been pre-binned.
For this to work, the index of each value in the categories
array is divided by the array length - 1 and passed to d3.interpolateYlGnBu()
.
Built with blockbuilder.org
https://d3js.org/d3.v4.min.js
https://d3js.org/d3-scale-chromatic.v1.min.js
https://cdnjs.cloudflare.com/ajax/libs/d3-legend/2.24.0/d3-legend.js