【问题标题】:Subset of colorbrewer set in D3D3 中设置的 colorbrewer 的子集
【发布时间】:2015-03-09 17:15:27
【问题描述】:
我只想使用 colorbrewer.js 中“Blues”颜色集中的 5 种最暗的颜色。我怎么做?我找不到任何涵盖它的文档。这是我的代码:
var colorScale = d3.scale.quantize()
.domain([0, maxInteractions*2])
.range(colorbrewer.Blues[9]);
【问题讨论】:
标签:
javascript
d3.js
colorbrewer
【解决方案1】:
colorbrewer.Blues[9] 只是一个颜色数组。您可以使用旧的array.slice() 来获取最后五个元素。
colorbrewer.Blues[9]
//["#f7fbff", "#deebf7", "#c6dbef", "#9ecae1", "#6baed6", "#4292c6", "#2171b5", "#08519c", "#08306b"]
colorbrewer.Blues[9].slice(4)
//["#6baed6", "#4292c6", "#2171b5", "#08519c", "#08306b"]