Saturday, September 27, 2025
HomeLanguagesJavascriptD3.js time.tickFormat() Function

D3.js time.tickFormat() Function

The time.tickFormat() function in D3.js is used to return a time format function suitable for displaying tick values. It returns the default time format when the specifier is not specified.

Syntax:

time.tickFormat( count, specifier )

Parameters: This function accepts two parameters as given above and described below:

  • count: It specifies the number of tick values.
  • specifier: It is the string that will be used as the specifier. It is of the format type “s”.

Return Values: This function does not return anything.

Below programs illustrate the time.tickFormat() function in D3.js:

Example 1:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src="https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h1 style="color: green">neveropen</h1>
  
    <p>time.tickFormat() Function </p>
  
    <script>
        var time = d3.scaleTime()
  
            // Specify the domain and range
            .domain([2001 - 01 - 01, 2005 - 01 - 02])
            .range([1, 100]);
  
        var ticks = time.ticks(1);
  
        // Specify the format of the ticks
        var tickFormat = time.tickFormat(1, "%Y-%m-%d ");
  
        document.write("<h3>" +
            ticks.map(tickFormat) + "</h3>");
    </script>
</body>
  
</html>


Output:

Example 2:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src="https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h1 style="color: green">neveropen</h1>
  
    <p>time.tickFormat() Function </p>
  
    <script>
        var time = d3.scaleTime()
  
            // Specify the domain and range
            .domain([2001 - 01 - 01, 2005 - 01 - 02])
            .range([1, 100]);
  
        var ticks = time.ticks(1);
  
        // Specify the format of the ticks
        var tickFormat = time.tickFormat(0, "%I %p");
  
        document.write("<h3>" +
            ticks.map(tickFormat) + "</h3>");
    </script>
</body>
  
</html>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32322 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6690 POSTS0 COMMENTS
Nicole Veronica
11857 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11912 POSTS0 COMMENTS
Shaida Kate Naidoo
6803 POSTS0 COMMENTS
Ted Musemwa
7073 POSTS0 COMMENTS
Thapelo Manthata
6763 POSTS0 COMMENTS
Umr Jansen
6768 POSTS0 COMMENTS