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


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


如果給出了域中的值,則使用D3.js中的d3.continuous()函數從範圍中返回相應的值。

用法:

d3.scaleLinear().domain(array of values).range(array of values);

參數:該函數不接受任何參數。


返回值:此函數返回域值的相應範圍值。

以下程序說明了D3.js中的d3.continuous()函數:

範例1:

<!DOCTYPE html> 
<html> 
      
<head> 
    <title> 
        D3.js | d3.continuous() Function 
    </title> 
      
    <script src =  
        "https://d3js.org/d3.v4.min.js"> 
    </script> 
</head> 
  
<body> 
    <script> 
          
        // Calling the scaleLinear() function 
        var A = d3.scaleLinear().domain([10, 50]) 
                .range([0, 100]); 
          
        // Getting the corresponding range for 
        // the domain value 
        console.log(A('15')); 
        console.log(A('20')); 
        console.log(A('25')); 
        console.log(A('30')); 
    </script> 
</body> 
  
</html>

輸出:

12.5
25
37.5
50

範例2:

<!DOCTYPE html> 
<html> 
      
<head> 
    <title> 
        D3.js | d3.continuous() Function 
    </title> 
      
    <script src =  
        "https://d3js.org/d3.v4.min.js"> 
    </script> 
</head> 
  
<body> 
    <script> 
          
        // Calling the scaleLinear() function 
        var A = d3.scaleLinear().domain([1, 5]) 
                .range([0, 10]); 
           
        // Getting the corresponding range for 
        // the domain value 
        console.log(A('1')); 
        console.log(A('2')); 
        console.log(A('3')); 
        console.log(A('4')); 
    </script> 
</body> 
  
</html>

輸出:

0
2.5
5
7.5

參考: https://devdocs.io/d3~5/d3-scale#_continuous



相關用法


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