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


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


D3.js中的time.copy()函数用于构造并返回原始比例的副本。对原始比例进行的更改不会影响复印比例,反之亦然。

用法:

time.copy()

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

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

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



范例1:

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <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> 
    <h1 style="color:green;">GeeksforGeeks</h1> 
  
    <p>time.copy() Function </p> 
  
    <script> 
  
        var time = d3.scaleTime() 
  
            // Setting domain and range 
            // for the scale 
            .domain([1, 100]) 
            .range([1, 10]); 
  
        // Creating a copy of the scale 
        var copy = time.copy(); 
  
        document.write("<h3>time(1):" + 
            time(1) + "</h3>"); 
        document.write("<h3>time(100):" + 
            time(100) + "</h3>"); 
        document.write("<p> copy scale:</p>"); 
          
    document.write("<h3>copy(100):" + 
            copy(100) + "</h3>"); 
        document.write("<h3>copy(1):" + 
            copy(1) + "</h3>"); 
    </script> 
</body> 
  
</html>

输出:

范例2:

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <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> 
    <h1 style="color:green;">GeeksforGeeks</h1> 
  
    <p>time.copy() Function </p> 
  
    <script> 
  
        var time = d3.scaleTime() 
  
            // Setting domain and range 
            // for the scale. 
            .domain([1, 100]) 
            .range([1, 10]); 
  
        // Creating a copy of the scale 
        var copy = time.copy(); 
  
        document.write("<h3>time(1000):" + 
            time(1000) + "</h3>"); 
        document.write("<h3>time(100000):" + 
            time(10000) + "</h3>"); 
  
        // Using clamp on the copy of the scale 
        document.write( 
    "<p> copy scale with clamp function.</p>"); 
      
        copy.clamp(true); 
        document.write("<h3>copy(1000):" + 
            copy(1000) + "</h3>"); 
        document.write("<h3>copy(10000):" + 
            copy(10000) + "</h3>"); 
    </script> 
</body> 
  
</html>

输出:




相关用法


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