如何将 d3-scale-chromatic 函数与 [0, 1] 以外的域一起使用?

How can I use d3-scale-chromatic functions with a domain other than [0, 1]?

这是我的代码:

var color = d3.scaleLinear()
    .domain([0, 10000])
    .interpolate(d3.interpolateBlues);
console.log(color(5000));

我没有告诉我 5000 对应浅蓝色,而是收到错误 "r0 is not a function"。我做错了什么?

好的,明白了。如果使用定义范围本身的函数,例如 d3.interpolateBlues,则必须使用 d3.scaleSequential 而不是 d3.scaleLinear。正确的代码是:

var color = d3.scaleSequential(d3.interpolateBlues)
    .domain([0, 10000])
console.log(color(5000));

https://github.com/d3/d3-scale#sequential-scales