Thursday, September 18, 2025
HomeLanguagesJavascriptD3.js ticks() Function

D3.js ticks() Function

The ticks()  function in D3.js is used to form an array of between a given range of start and stop both inclusive such that each element is uniformly and equally spaced.

Syntax:

d3.ticks(start,stop,count);

Parameters: This function accepts three parameters as mentioned above and described below:

  • start: It is the starting value from where we want the array element to be, it is inclusive.
  • stop: It is the starting value to which we want the array element to be, it is inclusive.
  • count: It is the number of elements we want in a given start and stops range.

Return value: It returns an array of nicely-rounded numbers.

Below given are a few examples of ticks() function.

Example 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>


Output:

Example 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>


Output:

RELATED ARTICLES

Most Popular

Dominic
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6660 POSTS0 COMMENTS
Nicole Veronica
11835 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7053 POSTS0 COMMENTS
Thapelo Manthata
6735 POSTS0 COMMENTS
Umr Jansen
6741 POSTS0 COMMENTS