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


d3.js quantile.invertExtent()用法及代碼示例

d3.js中的Quantile.invertExtent()函數用於為指定範圍內的對應值返回在指定域中存在的值的範圍。

用法:

quantile.invertExtent( value )

參數:此函數接受上麵給定並在下麵描述的單個參數:

  • value:它是與指定範圍相對應的值。

返回值:此函數從指定的域返回一個值。

以下示例程序旨在說明D3.js中的Quantile.invertExtent()函數:



範例1:

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <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> 
    <h1 style="color:green;"> 
        GeeksforGeeks 
    </h1> 
  
    <p>quantile.invertExtent() Function </p> 
  
    <script> 
        var quantile = d3.scaleQuantile() 
            // Setting domain for the scale. 
            .domain([1, 10]) 
            // Setting the range of the scale. 
            .range([0, 960]); 
  
        // Printing the output 
        document.write("<h3>" + 
            quantile.invertExtent(960) + 
            "</h3>"); 
        document.write("<h3>" + 
            quantile.invertExtent(0) + 
            "</h3>"); 
    </script> 
</body> 
  
</html>

輸出:

範例2:

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <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> 
    <h1 style="color:green;"> 
        GeeksforGeeks 
    </h1> 
  
    <p>quantile.invertExtent() Function </p> 
  
    <script> 
        var quantile = d3.scaleQuantile() 
            // Setting domain for the scale. 
            .domain([1, 10]) 
            // Setting the range of the scale. 
            .range(["red", "blue", "orange"]); 
  
        // Printing the output 
        document.write( 
            "<h3>quantile.invertExtent(\"blue\"):" + 
            quantile.invertExtent("blue") + "</h3>"); 
        document.write( 
            "<h3>quantile.invertExtent(\"red\"):" + 
            quantile.invertExtent("red") + "</h3>"); 
    </script> 
</body> 
  
</html>

輸出:




相關用法


注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js quantile.invertExtent() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。