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


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


D3.js中的sequence.copy()函数用于构造并返回原始比例的副本。原始比例的任何更改都不会影响复印比例,反之亦然。顺序刻度类似于连续刻度。在连续范围内,域和范围之间的映射是连续进行的。唯一的区别是此标度的输出范围由其内插器固定,并且该范围无法更改。

用法:

sequential.copy()

参数:该函数不接受任何参数。

返回值:此函数返回原始比例的副本。

下面给出了D3.js中sequence.copy()的一些示例:



范例1:

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <script src="https://d3js.org/d3.v6.min.js"> 
    </script> 
</head> 
  
<body> 
    <h2 style="color:green"> 
        GeeksforGeeks 
    </h2> 
  
    <h4> D3.js | sequential.copy() Function </h4> 
      
    <script> 
        var sequential = d3.scaleSequential(); 
  
        // Default scale is identity function 
        document.write("<h4>From original scale:</h4>") 
  
        document.write("<p>sequential(0.2):",  
                    sequential(0.2) + "</p>"); 
          
        document.write("<p>sequential(0.5):",  
                    sequential(0.5) + "</p>"); 
  
        // Creating copy of the original scale 
        var sequentialCopy = sequential.copy(); 
        document.write("<h4>From copy scale:</h4>") 
        document.write("<p>sequentialCopy(0.2):",  
                    sequentialCopy(0.2) + "</p>"); 
  
        document.write("<p>sequentialCopy(0.5):",  
                    sequentialCopy(0.5) + "</p>"); 
    </script> 
</body> 
  
</html>

输出:

范例2:复印比例的任何更改都不会影响原始比例。

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <script src="https://d3js.org/d3.v6.min.js"> 
    </script> 
</head> 
  
<body> 
    <h2 style="color:green"> 
        GeeksforGeeks 
    </h2> 
  
    <h4> D3.js | sequential.copy() Function </h4> 
  
    <script> 
        var sequential = d3.scaleSequential(); 
  
        // Default scale is identity function 
        document.write("<h4>From original scale:</h4>"); 
  
        document.write("<p>sequential(0.4):",  
                    sequential(0.4) + "</p>"); 
        document.write("<p>sequential(0.6):",  
                    sequential(0.6) + "</p>"); 
  
        // Creating copy of the original scale 
        var sequentialCopy = sequential.copy(); 
        sequentialCopy.domain([1, 2]); 
        document.write( 
        "<h4>From copy scale after changing domain:</h4>"); 
  
        document.write("<p>sequentialCopy(0.4):",  
                    sequentialCopy(0.4) + "</p>"); 
        document.write("<p>sequentialCopy(0.6):",  
                    sequentialCopy(0.6) + "</p>"); 
    </script> 
</body> 
  
</html>

输出:




相关用法


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