[D3] Create Labels from Numeric Data with Quantize Scales in D3 v4

Sometimes data needs to be converted from a continuous range, like test scores, to a discrete set of output values, like letter grades. In this lesson we’ll see how to use d3.scaleQuantize() to do exactly that.

function scaleQuantize(){
    var quantizeScale = d3.scaleQuantize()
        .domain([0, 100])
        .range(["red", "white", "green"]);

    console.log(quantizeScale(22)); // red
    console.log(quantizeScale(50)); // white
    console.log(quantizeScale(88)); // green

    // Get the boundaries domain for "white" color
    console.log(quantizeScale.invertExtent('white'));
}
原文地址:https://www.cnblogs.com/Answer1215/p/6127473.html