D3.js中的ticks()函數用於在開始和停止的給定範圍(包括兩個端點)之間形成一個數組,以使每個元素均勻且均勻地隔開。
用法:
d3.ticks(start,stop,count);
參數:此函數接受上述和以下所述的三個參數:
- start:它是我們希望數組元素所在的起始值,包括端點值。
 - stop:它是我們希望數組元素包含的起始值,包含在內。
 - count:它是我們在給定的起始和終止範圍內所需的元素數。
 
返回值:它返回nicely-rounded個數字的數組。
下麵給出的是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>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 10 elements in a range 
    // Note that each element is equally spaced 
    console.log(d3.ticks(10, 20, 20)) 
  </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 10 elements in a range 
    console.log(d3.ticks(10, 20)) 
  </script> 
</body> 
</html>輸出:

相關用法
- d3.js d3.lab()用法及代碼示例
 - PHP abs()用法及代碼示例
 - PHP Ds\Set xor()用法及代碼示例
 - PHP Ds\Set contains()用法及代碼示例
 - d3.js d3.hcl()用法及代碼示例
 - PHP sin( )用法及代碼示例
 - p5.js mag()用法及代碼示例
 - PHP Ds\Map xor()用法及代碼示例
 - PHP Ds\Map put()用法及代碼示例
 - PHP ord()用法及代碼示例
 - PHP cos( )用法及代碼示例
 - PHP Ds\Set add()用法及代碼示例
 - p5.js nf()用法及代碼示例
 - p5.js nfc()用法及代碼示例
 - d3.js d3.map.set()用法及代碼示例
 - p5.js arc()用法及代碼示例
 
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js ticks() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
