score:0

Write your own scale:

const color = [ 'red', 'green', 'blue' ];

var colorScale = d3.scaleOrdinal().domain(d3.range(1,11)).range(color);

function ordinalGroup(ordinalBase) {
  return function(v) {
    var domain = ordinalBase.domain();
    var range = ordinalBase.range();
    var idx = domain.indexOf(v);
    if (idx === -1) return range[0];
    return range[Math.floor(idx/(domain.length/range.length))];
  };
}

var colorGroup = ordinalGroup(colorScale);

console.log(colorScale.domain().map(d => [d, colorGroup(d)] ));
<script src="https://d3js.org/d3.v4.min.js"></script>


Related Query

More Query from same tag