在两个颜色值之间创建动态d3色标 [英] Create dynamic d3 color scale between two color values

查看:129
本文介绍了在两个颜色值之间创建动态d3色标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有颜色功能的d3饼图:

I have a d3 pie chart with a color function:

var color = d3.scale.ordinal()
            .range(['#0075B4', '#70B5DC']);

如果只有两个值/个,则可以使用.但是,如果还有更多,我想在给定的两者之间选择颜色.

If there are only two values/pieces, this works. But if there are more, I want to pick colors between the two given.

上面有3个饼,标有成本3"的饼的颜色介于#0075B4#70B5DC之间.

Above, with 3 pie pieces, the piece labelled "Cost 3" would have the color that is between #0075B4 and #70B5DC.

使用d3可以吗?这是到目前为止的内容: http://jsfiddle.net/9ruzntrr/1/

Is this possible with d3? Here is a jsfiddle of what I have so far: http://jsfiddle.net/9ruzntrr/1/

推荐答案

是的,只需以线性比例使用颜色即可.

Yes, just use colors in a linear scale:

var color = d3.scale.linear().domain([costMin,costMax])
        .range(['#0075B4', '#70B5DC']);

这篇关于在两个颜色值之间创建动态d3色标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆