Open In App

D3.js log.ticks() Function

Last Updated : 31 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The log.ticks() function is used to return ticks that are uniformly spaced within each integer power of base and each tick lies in scale’s domain. The values returned by ticks() lies in the domain. If the order of the in-domain is greater than count then one tick per power is returned. If the count is not given as a parameter then by default it is set to 10.

Syntax:

log.ticks([count]);

Parameters: This function accepts a single parameter as mentioned above and described below:

  • count: It is the number of ticks required.

Return Values: This function does not return anything.

Below given are a few examples of the function given above.

Example 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>
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h2 style="color:green;">
        GeeksforGeeks
    </h2>
      
    <p>D3.js log.ticks() Function </p>
  
    <script>
        var log = d3.scaleLog()
            .domain([1, 10])
            .range([1, 5])
            .ticks(8)
        document.write("<h3>" + log + "</h3>")
    </script>
</body>
  
</html>


Output:

Example 2: When base is set to 2




<!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>
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h2 style="color:green;">
        GeeksforGeeks
    </h2>
      
    <p>D3.js log.ticks() Function</p>
      
    <script>
        var log = d3.scaleLog()
            .domain([10, 100])
            .range(["red", "green"])
            .base(2)
        var tick = log.ticks(8)
        document.write("<h3>" + tick + "</h3>")
    </script>
</body>
  
</html>


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads