當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。