当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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


Continuous.interpolate()函数用于设置范围插值器工厂,该工厂用于为彼此相邻的范围中的每对值创建插值器。

用法:

continuous.interpolate( interpolate )

参数:该函数接受如上所述和以下描述的单个参数。

  • interpolator:此参数接受插值器。

返回值:此函数不返回任何内容。

以下示例程序旨在说明D3.js中的Continuous.interpolate()函数:



例:

HTML

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <meta charset="UTF-8" /> 
    <meta name="viewport" content= 
        "width=device-width, initial-scale=1.0"/> 
    <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> 
    <h2 style="color:green;">Geeksforgeeks</h2> 
  
    <p>continuous.interpolateRound() Function </p> 
  
    <script> 
        var continuous = d3.scaleLinear() 
            // Domain ranges -10, 0, 10 
            .domain([-10, 0, 10]) 
            // Range for the domain 
            .range([10, 20, 30, 40, 50, 60, 70, 80, 90]) 
            // Using interpolateRound 
            .interpolate(d3.interpolateRound); 
  
        document.write("<div>"); 
        document.write("<h3>" + continuous(1) + "</h3>"); 
        document.write("<h3>" + continuous(2) + "</h3>"); 
        document.write("<h3>" + continuous(3.5) + "</h3>"); 
        document.write("<h3>" + continuous(4.5) + "</h3>"); 
        document.write("<h3>" + continuous(5.5) + "</h3>"); 
        document.write("<h3>"  
            + continuous(-2.5) + "</h3></div>"); 
    </script> 
</body> 
  
</html>

输出:




相关用法


注:本文由纯净天空筛选整理自tarun007大神的英文原创作品 D3.js continuous.interpolate() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。