当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


d3.js threshold.invertExtent()用法及代码示例


d3.js中的threshold.invertExtent()函数用于返回指定域中值的范围。

用法:

threshold.invertExtent(value);

参数:此函数接受上面给定并在下面描述的单个参数:

  • value:此参数采用给定范围内的值。

返回值:此函数从与给定输入值相对应的域中返回一个值。

下面给出的是上面给出的函数的一些例子。



范例1:

<!DOCTYPE html>  
<html lang="en">  
<head>  
    <meta charset="UTF-8" />  
    <meta name="viewport"
        path1tent="width=device-width,  
        initial-scale=1.0"/>  
    <script src= 
    "https://d3js.org/d3.v4.min.js"> 
    </script>  
    <script src= 
    "https://d3js.org/d3-color.v1.min.js"> 
    </script>  
    <script src= 
    "https://d3js.org/d3-interpolate.v1.min.js"> 
    </script>  
    <script src= 
    "https://d3js.org/d3-scale-chromatic.v1.min.js"> 
    </script>  
</head>  
<body>  
    <h2 style="color:green;">Geeks for geeks</h2> 
    <p>threshold.invertExtent() Function </p> 
    <script>  
        var threshold = d3.scaleThreshold() 
                    // Setting domain for the scale. 
                    .domain([1, 2, 3, 4]) 
                    .range(["red", "green", "blue"]); 
        let val1=threshold.invertExtent("green"); 
        let val2=threshold.invertExtent("blue"); 
        document.write("<h4>["+val1+"]</h4>"); 
        document.write("<h4>["+val2+"]</h4>"); 
    </script>  
</body>  
</html>

输出:

范例2:

<!DOCTYPE html>  
<html lang="en">  
<head>  
    <meta charset="UTF-8" />  
    <meta name="viewport"
        path1tent="width=device-width,  
        initial-scale=1.0"/>  
    <script src= 
    "https://d3js.org/d3.v4.min.js"> 
    </script>  
    <script src= 
    "https://d3js.org/d3-color.v1.min.js"> 
    </script>  
    <script src= 
    "https://d3js.org/d3-interpolate.v1.min.js"> 
    </script>  
    <script src= 
    "https://d3js.org/d3-scale-chromatic.v1.min.js"> 
    </script>  
</head>  
<body>  
    <h2 style="color:green;">Geeks for geeks</h2> 
    <p>threshold.invertExtent() Function </p> 
    <script>  
        var threshold = d3.scaleThreshold() 
                    // Setting domain for the scale. 
                    .domain([1, 2, 3, 4]) 
                    .range([10, 20, 30, 40, 50]); 
        let val1=threshold.invertExtent(10); 
        let val2=threshold.invertExtent(50); 
        let val3=threshold.invertExtent(20); 
        document.write("<h4>["+val1+"]</h4>"); 
        document.write("<h4>["+val2+"]</h4>"); 
        document.write("<h4>["+val3+"]</h4>"); 
    </script>  
</body>  
</html>

输出:




相关用法


注:本文由纯净天空筛选整理自tarun007大神的英文原创作品 D3.js threshold.invertExtent() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。