HomeLanguagesJavascriptD3.js continuous.tickFormat() Function

D3.js continuous.tickFormat() Function

The continuous.tickFormat() function is used to change the format of the tick values. It returns a number format function that is suitable for displaying a tick value.

Syntax:

continuous.tickFormat( count, specifier )

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

  • count: It is the number of tick values to be used. It is an optional parameter.
  • specifier: It is a string which specifies the format to be used. It is an optional parameter.

Return Values: This function does not return anything.

The program below illustrates the continuous.tickFormat() function in D3.js:

Example 1:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h1 style="color: green">
        neveropen
    </h1>
  
    <p>continuous.tickFormat() Function </p>
  
    <script>
        var x = d3.scaleLinear()
            .domain([0, 1])
            .range([1, 2, 3, 4, 5, 6]);
  
        var ticks = x.ticks(3)
        var tickFormat = x.tickFormat(3, " %");
  
        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=
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h1 style="color: green">
        neveropen
    </h1>
  
    <p>continuous.tickFormat() Function </p>
  
    <script>
        var x = d3.scaleLinear()
            .domain([0, 1])
            .range(["red", "blue", "green", "orange"]);
  
        var ticks = x.ticks(5)
        var tickFormat = x.tickFormat(5, " $");
  
        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

4 COMMENTS

Most Popular

Dominic
32533 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6913 POSTS0 COMMENTS
Nicole Veronica
12029 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12132 POSTS0 COMMENTS
Shaida Kate Naidoo
7043 POSTS0 COMMENTS
Ted Musemwa
7280 POSTS0 COMMENTS
Thapelo Manthata
7000 POSTS0 COMMENTS
Umr Jansen
6986 POSTS0 COMMENTS