當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


d3.js band.copy()用法及代碼示例

band.copy()函數用於構造並返回具有相同域和範圍的當前音階的副本。對任何比例進行的任何更改都是相互獨立的,即原始比例的更改不會影響複印比例,反之亦然。

用法:

band.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> 
      
</head>  
<body>  
    <script>  
    // Creating the band scale  
    //with specified domain and range. 
        var band = d3.scaleBand() 
                    .domain([10, 20, 30, 40, 50]) 
                    .range([10, 100]); 
    // Discrete values are automatically created  
    // By the band function 
    // Band of the range is [10, 100] 
        console.log("band(10):", band(10)); 
        console.log("band(50):", band(50)); 
  
        var bandCopy = band.copy(); 
        console.log("bandCopy(10):", bandCopy(10)); 
        console.log("bandCopy(50):", bandCopy(50)); 
    </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"/>  
    <title>GeekforGeeks</title>  
    <script src = 
    "https://d3js.org/d3.v4.min.js"> 
    </script> 
      
</head>  
<body>  
    <script>  
    // Creating the band scale 
  // with specified domain and range. 
        var band = d3.scaleBand() 
                .domain([10, 20, 30, 40, 50]) 
                .range([1, 10]); 
// Discrete values are automatically created  
    // By the band function 
    // Band of the range is [1, 10] 
        console.log( 
"Before any type of change in original scale:"); 
        console.log("band(10):", band(10)); 
        console.log("band(50):", band(50)); 
        // Making copy of the original scale 
        var bandCopy = band.copy(); 
        console.log( 
"When the range of the original "+ 
"scale is changed to rangeRound:"); 
        // Making changes to the original scale 
        band.rangeRound([1, 10]); 
        console.log("band(10):", band(10)); 
        console.log("band(50):", band(50)); 
        console.log("Output of the copy scale:"); 
        console.log("bandCopy(10):", bandCopy(10)); 
        console.log("bandCopy(50):", bandCopy(50)); 
    </script>  
</body>  
</html>

輸出:




相關用法


注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js band.copy() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。