我正在尝试在印度 map 图表上应用等值线。但无法实现结果 - My demo
var colorScale = d3.scale.quantile()
.domain([0, buckets - 1, d3.max(json, function (d) { return json.total; })])
.range(colors);
我能感觉到上面和下面的代码是原因,但我无法解决。
india.transition().duration(1000)
.style("fill", function(d) { return colorScale(json.total); });
颜色引用取自 bl.ocks.org/tjdecke/5558084
最佳答案
除了 other answer 中解释的问题,你的色标是错误的。现在它返回这个数组作为域:
[0, 8, 9765]
这可能不是您想要的。
这里是一个不同的尺度,从 0 到最大值 total
等间隔划分域:
var maxTotal = d3.max(json.features, function(d) {
return d.total
});
var colorScale = d3.scale.quantile()
.domain(d3.range(buckets).map(function(d) {
return (d / buckets) * maxTotal
}))
.range(colors);
现在,这是域:
[0, 1085, 2170, 3255, 4340, 5425, 6510, 7595, 8680]
关于javascript - 试图在印度 map 上应用等值线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47474268/