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


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

d3.interpolateCubehelixLong()函數用於返回兩個給定顏色A和B之間的立方螺旋顏色空間插值器。它使用色相之間的最短路徑。

用法:

d3.interpolateCubehelixLong(a, b);

參數:它采用上麵給出和下麵描述的兩個參數。

  • a:它是字符串格式的顏色名稱。
  • b:它也是字符串格式的顏色的名稱。

返回值:它返回函數。

範例1:



HTML

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content= 
        "width=device-width,initial-scale=1.0"> 
    
    <!--Fetching from CDN of D3.js -->
    <script type="text/javascript" 
        src="https://d3js.org/d3.v4.min.js"> 
    </script> 
</head> 
  
<body> 
  
    <script> 
        console.log("Type of the function is:", 
            typeof(d3.interpolateCubehelixLong("white", "red"))) 
  
        console.log( 
            d3.interpolateCubehelixLong("blue", "white")(0.9)) 
  
        console.log( 
            d3.interpolateCubehelixLong("white", "green")(0.1))  
    </script> 
</body> 
  
</html>

輸出:

範例2:

HTML

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content= 
        "width=device-width,initial-scale=1.0"> 
  
      <!--Fetching from CDN of D3.js -->
    <script type="text/javascript" 
        src="https://d3js.org/d3.v4.min.js"> 
    </script> 
    
    <style> 
        .bx1, 
        .bx2 { 
            width:100px; 
            height:100px; 
        } 
    </style> 
</head> 
  
<body> 
      
<p>D3.interpolateCubehelixLong()</p> 
  
    <div class="bx1"></div> 
    <div class="bx2"></div> 
      
    <script> 
        let color1 = 
            d3.interpolateCubehelixLong("green", "white")(0.1) 
        let color2 = 
            d3.interpolateCubehelixLong("white", "green")(0.1) 
        let bx1 = document.querySelector(".bx1"); 
        bx1.style.backgroundColor = color1; 
        let bx2 = document.querySelector(".bx2"); 
        bx2.style.backgroundColor = color2;  
    </script> 
</body> 
  
</html>

輸出:注意將綠色作為第一個參數和將白色作為第一個參數之間的區別。




相關用法


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