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


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

d3.js中的threshold.copy()函數用於創建和返回閾值刻度的精確副本。原始比例的任何更改都不會影響複印比例。

用法:

threshold.copy();

參數:此函數不接受任何參數。

返回值:此函數返回原始閾值刻度的精確副本。

範例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.v4.min.js"> 
    </script> 
</head> 
  
<body> 
    <h2 style="color:green">GeekforGeeks</h2> 
  
    <p>threshold.copy() Function </p> 
  
    <script> 
        var threshold = d3.scaleThreshold() 
            // Domain 
            .domain([1, 2, 3, 4]) 
            // Range for the domain 
            .range([10, 20, 30, 40, 50]); 
  
        document.write("<h3>threshold(1):"  
            + threshold(1) + "</h3>"); 
        document.write("<h3>threshold(3):"  
            + threshold(3) + "</h3>"); 
  
        document.write( 
            "<p> This is from copy scale.</p>"); 
  
        var thresholdCopy = threshold.copy(); 
          
        document.write("<h3>thresholdCopy(1):"  
            + thresholdCopy(1) + "</h3>"); 
        document.write("<h3>thresholdCopy(3):"  
            + thresholdCopy(3) + "</h3>"); 
    </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.v4.min.js"> 
    </script> 
</head> 
  
<body> 
    <h2 style="color:green">GeekforGeeks</h2> 
  
    <p>threshold.copy() Function </p> 
  
    <script> 
        var threshold = d3.scaleThreshold() 
            // Domain 
            .domain([1, 2, 3, 4]) 
            // Range for the domain 
            .range([10, 20, 30, 40, 50]); 
  
        var thresholdCopy = threshold.copy(); 
  
        document.write( 
            "<div style=line-height:5px><h3>threshold(1):"  
            + threshold(1) + "</h3>"); 
  
        document.write("<h3>threshold(3):"  
                + threshold(3) + "</h3>"); 
  
        // Making changes on the original scale 
        threshold.range([100, 200, 300, 400, 500]); 
        document.write( 
        "<p> After making changes in the original scale</p>"); 
  
        document.write("<h3>threshold(3):"  
                + threshold(3) + "</h3>"); 
  
        document.write("<p> This is from copy scale.</p>"); 
  
        document.write("<h3>thresholdCopy(1):"  
                + thresholdCopy(1) + "</h3>"); 
        document.write("<h3>thresholdCopy(3):"  
                + thresholdCopy(3) + "</h3></div>"); 
    </script> 
</body> 
  
</html>

輸出:




相關用法


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