js中反转颜色标度

js中反转颜色标度

本文介绍了在d3.js中反转颜色标度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在d3中创建一个具有颜色域和数字范围的缩放吗?

Is it possible to create a scale in d3 with a color domain and a number range?

我尝试了以下操作:

  var colorScale = d3.scale.linear().range(["red", "white"]).domain([3, 9.5])
  console.log('cs:', colorScale(4));
  console.log('cs:', colorScale.invert(colorScale(4)));

但输出不是很令人鼓舞:

But the output isn't very encouraging:

cs: #ff2727
cs: NaN

这是不可能的任务还是我做错了什么?

Is this an impossible task or am I doing something wrong?

推荐答案

根据:

不能这样做。

这篇关于在d3.js中反转颜色标度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 05:38