How to get quantize values

孤人 提交于 2020-02-03 09:46:44

问题


is there a way to get the start and end values of the quantizes of an quantize scale. The range is defined by 5 colors ans the domain by d3.min and d3.max function on my data from an json file. I need them for my legend of an choropleth map. Thank you for helping.

Carsten

Thats my code

var quantizecolors = ["#d7191c","#fdae61","#ffffbf", "#a6d96a","#1a9641"];
var colorEnerg = d3.scale.quantize().range(quantizecolors);
colorEnerg.domain([
                            d3.min(collection.features, function(d){return d.properties.EB/d.properties.BEVZ;}),
                            d3.max(collection.features, function(d){return d.properties.EB/d.properties.BEVZ;})
                            ]); 

回答1:


I assume that you're asking about the minimum and maximum domain values. Apart from saving them when you're setting them, you can also call colorEnerg.domain() without any values, which will return the array [min, max].

You can get the position of the breaks by computing the number and position of intervals:

var dom = colorEnerg.domain(),
    l = (dom[1] - dom[0])/colorEnerg.range().length,
    breaks = d3.range(0, colorEnerg.range().length).map(function(i) { return i * l; });


来源:https://stackoverflow.com/questions/20550840/how-to-get-quantize-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!