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

D3.js timeout() Function

The d3.timeout() function in D3.js is used to automatically stop the function or the timer after a particular interval of time. It works same as setTimeOut() function in JavaScript.

Syntax:

d3.timeout(callback, delay);

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

  • callback: It is the function to be stopped after a particular delay.
  • delay: It is the time after which the function will be stopped.

Return Value: This function returns an object.

Below given are a few examples of the above function.

Example 1: When no delay is given.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
    "width=device-width, initial-scale=1.0">
</head>
  
<body>
    <!-- Fetching from CDN of D3.js -->
    <script type="text/javascript" 
        src="https://d3js.org/d3.v4.min.js">
    </script>
      
    <script>
        let delay = 0
        let func = function (e) {
            console.log(e);
            console.log("It will run one time"
                + " with delay equal ", delay);
        }
        var timer = d3.timeout(func, delay);
  
        func = function (e) {
            console.log(e);
            console.log(
                "It will run one time with no delay");
        }
        var timer = d3.timeout(func);
        console.log("Return Type is: ", typeof timer);
    </script>
</body>
  
</html>


Output:

Example 2: When the delay is given.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
</head>
  
<body>
    <!-- Fetching from CDN of D3.js -->
    <script type="text/javascript" 
        src="https://d3js.org/d3.v4.min.js">
    </script>
      
    <script>
        let delay = 1000
        let func = function (e) {
            console.log(e);
            console.log("It will run one time"
                + " with delay equal ", delay);
        }
        var timer = d3.timeout(func, delay);
  
        func = function (e) {
            console.log(e);
            console.log("This will be printed first");
        }
        var timer = d3.timeout(func);
    </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
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6662 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