Q:

why doesn't d3.scale Quantize generate discrete values over my continuous range

I tried to use d3.scaleQuantize() to create a scale to outputs a number of discrete quantities defined by the range. Below is my code. 
var d3 = require("d3")

var domain = ["a", "b","c","d"]
var color = d3.scaleQuantize()
    .domain(domain)
    .range([1,1000]);
domain.forEach(function(d){
    console.log(`${d} = ${color(d)}`);
});

The output of above code is as below:
"a = 1000"
"b = 1000"
"c = 1000"
"d = 1000"

I expect each element in the domain array should be scaled to the range of [1,1000]. Why doesn't it work?

A:

Quantize scales are similar to linear scales, except they use a discrete rather than continuous range. The continuous input domain is divided into uniform segments based on the number of values in (i.e., the cardinality of) the output range.

You misunderstood quantize scale in d3. D3's quantize scale requires a continuous domain input, but in your case, your input is discrete. With quantize scale, the input is essentially divided into "buckets" depending on the number of values in the range array, again, because your domain is discrete, it can't correctly divide up your input array. To achieve what you need, use Ordinal Scale

