官术网_书友最值得收藏!

Color interpolation and color schemes

Besides the d3.interpolateReds function, D3 provides a large number of other color scales and schemes. In this sample, we directly return a color based on the provided i argument (which corresponds to a segment of our donut). We could also use a D3 scale for this:

var scale = d3.scaleSequential(d3.interpolateReds).domain([0, 5]);

D3 provides a large number of color scales you can use. It comes with the following ranges out-of-the-box:

But if you include the https://github.com/d3/d3-scale-chromatic  module, you get a large number of additional colors that you can use (the following image just shows a subset. If you want to see all the colors, open <DVD3>/chapter-02/colors.html in your browser):

The previous two images show a sequential set of colors. If you want to use a specific color scheme (for example, a fixed set of colors), you can also use D3 for that. When you use the d3-scala-chromatic module you get the following standard color schemes:

To use these color schemes, you need to create your scale in a slightly different way:

var scale = d3.scaleQuantize().domain([0, width]).range(d3.schemeAccent);

With a scaleQuantize function, the input range (zero to width) is mapped to an array of values (d3.schemeAccent). D3 will calculate which color is mapped to a specific input value. So, enough about the colors, let's go back to drawing the gray donut.

主站蜘蛛池模板: 宝应县| 南和县| 垦利县| 哈尔滨市| 越西县| 基隆市| 宁津县| 榆林市| 蚌埠市| 徐闻县| 瑞昌市| 辽源市| 阿拉善左旗| 湘乡市| 三都| 新晃| 若尔盖县| 温州市| 河间市| 柳州市| 克东县| 山丹县| 高唐县| 合水县| 平邑县| 手游| 潮安县| 饶河县| 弥勒县| 洱源县| 托克托县| 炉霍县| 沙田区| 开封县| 衡南县| 广安市| 吉木乃县| 同江市| 延庆县| 沙雅县| 北辰区|