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


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

分位數.domain()函數用於設置分位數標度的域。給定的域數組不能為空,並且必須至少包含一個數字值。

用法:

quantile.domain([domain]);

參數:該函數僅采用上麵給出的和下麵描述的一個參數。

  • domain:此參數設置刻度的範圍,即最小值和最大值。它接受離散數值數組。該數組必須至少包含一個數字值。

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

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



範例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.domain() Function</p> 
  
    <script> 
        var quantile = d3.scaleQuantile() 
            // Setting domain for the scale 
            .domain([1000]) 
            // Setting the range of the scale 
            .range([16]); 
  
        // Printing the output 
        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> 
  
    <p>quantile.domain() Function</p> 
  
    <script> 
        var quantile = d3.scaleQuantile() 
            // Setting domain for the scale 
            .domain([1, 2, 3, 4]) 
            // Setting the range of the scale 
            .range([6, 16, 24, 28]); 
  
        // Printing the output 
        document.write("<h3>quantile(1):" 
                + quantile(1) + "</h3>"); 
        document.write("<h3>quantile(2):"  
                + quantile(2) + "</h3>"); 
        document.write("<h3>quantile(3):"  
                + quantile(3) + "</h3>"); 
        document.write("<h3>quantile(4):"  
                + quantile(4) + "</h3>"); 
    </script> 
</body> 
  
</html>

輸出:




相關用法


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