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


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


log.copy()函数用于创建并返回原始比例的精确副本。该副本不是原始比例的参考,因此原始比例的任何更改都不会影响副本比例。

用法:

log.copy()

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

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

下面给出的是上面给出的函数的一些例子。



范例1:

<!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.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>D3.js log.copy() Function</p> 
  
    <script> 
        var log = d3.scaleLog() 
            .domain([1, 20]) 
            .range([10, 20, 30, 40, 50, 60]); 
  
        // Using log.copy() Function 
        let logCopy = log.copy(); 
        document.write("<h3>Original scale:" 
                + log(1) + "</h3>"); 
  
        document.write("<h3>Copy scale:"  
                + logCopy(1) + "</h3>"); 
    </script> 
</body> 
  
</html>

输出:

范例2:

<!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.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>D3.js log.copy() Function</p> 
  
    <script> 
        var log = d3.scaleLog() 
            .domain([1, 20]) 
            .range([10, 20, 30, 40, 50, 60]); 
  
        // Using log.copy() Function 
        let logCopy = log.copy(); 
        document.write("<h3>Original scale:"  
                    + log(15) + "</h3>"); 
  
        document.write("<h3>Copy scale:"  
                    + logCopy(15) + "</h3>"); 
                      
        log.interpolate(d3.interpolateRound); 
  
        document.write("<p>Changes in original " 
            + "scale does not affect copy scale.</p>"); 
  
        document.write("<h3>Original scale:"  
                        + log(15) + "</h3>"); 
  
        document.write("<h3>Copy scale:"  
                    + logCopy(15) + "</h3>"); 
    </script> 
</body> 
  
</html>

输出:




相关用法


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