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


d3.js sequential.interpolator()用法及代码示例


顺序刻度与连续刻度非常相似。在连续规模上,域和范围之间的映射是连续进行的。唯一的区别是此标度的输出范围由其内插器固定,并且该范围无法更改。

d3.js中的sequence.interpolator()函数用于配置比例尺的插值器。如果指定了插值器,它将比例尺的插值器设置为指定的函数,否则返回标尺的当前插值器。

用法:

sequential.interpolator([interpolator]);

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

  • interpolator:这需要内插器函数。如果未指定插值器,则返回标尺的当前插值器。

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



范例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.v6.min.js"> 
    </script> 
</head> 
  
<body> 
    <h2 style="color:green"> GeeksforGeeks </h2> 
  
    <h4> D3.js | sequential.interpolator() Function</h4> 
    <script> 
        var sequential = d3.scaleSequential() 
  
            // Setting the interpolator of the scale. 
            .interpolator((t) => t * 2); 
  
        document.write("<p>sequential(2):",  
                    sequential(2) + "</p>"); 
  
        document.write("<p>sequential(4):",  
                    sequential(4) + "</p>"); 
  
        document.write("<p>sequential(10):",  
                    sequential(10) + "</p>"); 
  
        document.write("<p>sequential(20):",  
                    sequential(20) + "</p>"); 
    </script> 
</body> 
  
</html>

输出:

范例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.v6.min.js"> 
    </script> 
</head> 
  
<body> 
    <h2 style="color:green"> GeeksforGeeks </h2> 
  
    <h4>D3.js | sequential.interpolator() Function</h4> 
  
    <script> 
        var sequential = d3.scaleSequential() 
            // Setting the interpolator of the scale. 
            .interpolator(d3.interpolateSpectral) 
            // Setting the domain of the scale. 
            .domain([1, 100]); 
        document.write("<p>sequential(2):",  
                    sequential(2) + "</p>"); 
  
        document.write("<p>sequential(4):",  
                    sequential(4) + "</p>"); 
  
        document.write("<p>sequential(10):",  
                    sequential(10) + "</p>"); 
  
        document.write("<p>sequential(20):",  
                    sequential(20) + "</p>"); 
    </script> 
</body> 
  
</html>

输出:




相关用法


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