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


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

分位數.range()函數用於設置分位數的範圍。範圍數組中值的數量決定了此函數創建的分位數。

用法:

quantile.range([range]);

參數:該函數接受如上所述和以下描述的單個參數。

  • range:此參數接受離散值數組。

返回值:此函數不返回任何值。

以下示例說明了D3.js中的Quantile.range()函數:



範例1:

HTML

<!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> 
</head> 
  
<body> 
    <h2 style="color:green">GeekforGeeks</h2> 
  
    <p>quantile.range() Function</p> 
  
    <script> 
        var quantile = d3.scaleQuantile() 
            .range([6, 12, 18, 24]); 
  
        // Printing the output 
        document.write("when domain is not specified") 
        document.write("<h3>quantile(10):"  
                + quantile(10) + "</h3>"); 
        document.write("<h3>quantile(20):"  
                + quantile(20) + "</h3>"); 
    </script> 
</body> 
  
</html>

輸出:

範例2:

HTML

<!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> 
</head> 
  
<body> 
    <h2 style="color:green">GeekforGeeks</h2> 
    <h3>quantile.range() Function</h3> 
    <script> 
        var quantile = d3.scaleQuantile() 
            // Setting domain for the scale. 
            .domain([10, 20, 30, 40]) 
            // Discrete range 
            .range([6, 12, 18, 24]); 
  
        // Printing the output 
        document.write("<span>quantile(10):"  
            + quantile(10) + "</span><br>"); 
        document.write("<span>quantile(20):"  
            + quantile(20) + "</span><br>"); 
        document.write("<span>quantile(30):"  
            + quantile(30) + "</span><br>"); 
        document.write("<span>quantile(40):"  
            + quantile(40) + "</span><br>"); 
    </script> 
</body> 
  
</html>

輸出:




相關用法


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