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


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

log.range()函數將對數刻度的範圍設置為必須包含兩個或兩個以上值的指定值數組。範圍內的元素可以是數字或字符串。

用法:

log.range([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> 
    <script> 
        var log = d3.scaleLog() 
  
            // Setting the domain for the scale. 
            .domain([1, +10]) 
              
            // Setting the range for the scale 
            .range([1, 2, 3, 4, 5]); 
        console.log(log(1)); 
        console.log(log(10)); 
    </script> 
</body> 
  
</html>

輸出:

1 
2

範例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> 
    <script> 
        var log = d3.scaleLog() 
  
            // Setting the domain for the scale 
            .domain([10, 20]) 
  
            // Setting the range for the scale 
            .range(["red", "green", "blue"]); 
        console.log(log(10)); 
        console.log(log(15)); 
        console.log(log(20)); 
    </script> 
</body> 
  
</html>

輸出:

rgb(255, 0, 0)
rgb(106, 75, 0)
rgb(0, 128, 0)




相關用法


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