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


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

D3.js中的tickStep()函數用於返回數組中相鄰刻度值之間的差。

用法:

tickStep(start,stop,count);

參數:此函數接受上述和以下所述的三個參數:

  • start:它是我們希望數組元素所在的起始值,包括端點值。
  • stop:它是我們希望數組元素包含的起始值,包含在內。
  • count:它是我們在給定的起始和終止範圍內所需的元素數。

返回值:它以浮點表示形式返回該步長值。

下麵給出的是ticks()函數的一些示例



範例1:

HTML

<!DOCTYPE html> 
<html lang="en"> 
<head> 
  <meta charset="UTF-8"> 
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0"> 
  <title>D3 tickStep() Function</title> 
</head> 
<body> 
  <!--fetching from CDN of D3.js -->
  <script type = "text/javascript" 
          src = "https://d3js.org/d3.v4.min.js"> 
  </script> 
  <script> 
    // Choosing 10 elements in a range 
    let step=d3.tickStep(10, 20, 10); 
    console.log("Difference between each tick value is:",step); 
      
  </script> 
</body> 
</html>

輸出:

範例2:

HTML

<!DOCTYPE html> 
<html lang="en"> 
<head> 
  <meta charset="UTF-8"> 
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0"> 
  <title>Document</title> 
</head> 
<body> 
  <!--fetching from CDN of D3.js -->
  <script type = "text/javascript" 
          src = "https://d3js.org/d3.v4.min.js"> 
  </script> 
  <script> 
    // Choosing 1000 elements in a range 
    let step=d3.tickStep(10, 15, 1000); 
    console.log("Difference between"+ 
                " each tick value is:",step); 
  
  </script> 
</body> 
</html>

輸出:

範例3:如果止損點少,則開始

HTML

<!DOCTYPE html> 
<html lang="en"> 
<head> 
  <meta charset="UTF-8"> 
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0"> 
  <title>Document</title> 
</head> 
<body> 
  <!--fetching from CDN of D3.js -->
  <script type = "text/javascript" 
          src = "https://d3js.org/d3.v4.min.js"> 
  </script> 
  <script> 
    // Choosing 1000 elements in a range 
    let step=d3.tickStep(10, 5, 1000); 
    console.log("Difference between"+ 
                " each tick value is:",step); 
  
  </script> 
</body> 
</html>

輸出:




相關用法


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