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


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

D3.js中的d3.scaleQuantile()的quantile()函數用於返回對應於給定輸入值的範圍內的值。此輸入值位於指定的域中。

用法:

quantile( value )

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

  • value:它采用位於域中的數值。

返回值:此函數返回對應於指定範圍的值。

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



例:

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>d3.scaleQuantile | quantile() Function </p> 
  
    <script> 
        var quantile = d3.scaleQuantile() 
  
            // Setting domain and range 
            // for the scale 
            .domain([1, 10]) 
            .range([0, 960]); 
  
        // Printing the output using the 
        // quantile() function 
        document.write( 
            "<h3>" + quantile(1) + "</h3>"); 
        document.write( 
            "<h3>" + quantile(5) + "</h3>"); 
        document.write( 
            "<h3>" + quantile(9) + "</h3>"); 
        document.write( 
            "<h3>" + quantile(10) + "</h3>"); 
    </script> 
</body> 
  
</html>

輸出:




相關用法


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