Thursday, February 5, 2026
HomeLanguagesJavascriptD3.js time.rangeRound() Function

D3.js time.rangeRound() Function

The time.rangeRound() function is used to set the range of the scale to the specified array of values along with setting the interpolator to intepolateRound.

Syntax:

time.rangeRound([range]);

Parameters: This function accepts one parameter that is given above and described below.

  • range: This parameter accepts an array of numbers or strings.

Return Value: This function does not return anything.

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

Example 1:

HTML




<!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="https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src="https://d3js.org/d3-interpolate.v1.min.js">
    </script>
    <script src="https://d3js.org/d3-scale-chromatic.v1.min.js">
    </script>
  
    <style>
        body {
            margin-left: 40px;
        }
  
        h2 {
            color: green;
        }
  
        div {
            float: left;
            width: 280px;
        }
    </style>
</head>
  
<body>
    <h2>Geeks for neveropen</h2>
    <p>time.rangeRound() Function </p>
      
    <script>
        var time = d3.scaleTime()
            // Setting domain for the scale.
            .domain([1, 10])
            // Setting the range of the scale.
            .range([1, 100]);
  
        document.write(
            "<div><h3>Without time.rangeRound()</h3>");
        document.write(
            "<h3>time(1.5): " + time(1.5) + "</h3>");
        document.write(
            "<h3>time(2): " + time(2) + "</h3>");
        document.write(
            "<h3>time(3.5): " + time(3.5) + "</h3>");
        document.write(
            "<h3>time(4.5): " + time(4.5) + "</h3></div>");
  
        var time = d3.scaleTime()
            // Setting domain for the scale.
            .domain([1, 10])
            // Setting the range of the scale.
            .rangeRound([1, 100]);
        document.write(
            "<div><h3>With time.rangeRound()</h3>");
        document.write(
            "<div><h3>time(1.5): " + time(1.5) + "</h3>");
        document.write(
            "<h3>time(2): " + time(2) + "</h3>");
        document.write(
            "<h3>time(3.5): " + time(3.5) + "</h3>");
        document.write(
            "<h3>time(4.5): " + time(4.5) + "</h3></div>");
    </script>
</body>
  
</html>


Output:

Example 2:

HTML




<!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="https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
  
    <style>
        body {
            margin-left: 40px;
        }
  
        h2 {
            color: green;
        }
    </style>
</head>
  
<body>
    <h2>Geeks for neveropen</h2>
    <p>time.rangeRound() Function </p>
    <script>
  
        var time = d3.scaleTime()
  
            // Setting domain for the scale.
            .domain([2001 - 01 - 01, 2000 - 01 - 02])
            .rangeRound([1, 10])
        document.write("<h3>time(2.4): " 
                + time(2.4) + "</h3>");
  
        document.write("<h3>time(2): " 
                + time(2) + "</h3>");
  
        document.write("<h3>time(6.4): " 
                + time(6.4) + "</h3>");
                  
        document.write("<h3>time(4.5): " 
                + time(4.5) + "</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
32487 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6861 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12071 POSTS0 COMMENTS
Shaida Kate Naidoo
6994 POSTS0 COMMENTS
Ted Musemwa
7233 POSTS0 COMMENTS
Thapelo Manthata
6945 POSTS0 COMMENTS
Umr Jansen
6926 POSTS0 COMMENTS