简体   繁体   English

D3以矩形显示线性颜色范围

[英]D3 show linear color range in rect

This may be a silly question but I can't seem to figure it out - is there a way in D3 to fill a rectangle based on a linear color scale? 这可能是一个愚蠢的问题,但我似乎无法弄清楚-D3中是否有一种方法可以根据线性色标来填充矩形? That is, I have a linear scale from white to green so I want to display a "legend" which is basically a rectangle with color transitioning from white to green. 也就是说,我具有从白色到绿色的线性比例,因此我想显示一个“传说”,它基本上是一个矩形,其颜色从白色过渡到绿色。 Is there a simple way to do this? 有没有简单的方法可以做到这一点?

What you are looking for is an SVG gradient . 您正在寻找的是SVG渐变 Here is an example in D3. 是D3中的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM