Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

D3.js continuous.rangeRound() Function

  • Last Updated : 23 Aug, 2020

The continuous.rangeRound() function is used set the range of the scale to the specified array of values. It also sets the interpolator to interpolatorRound. The rounding interpolator may be useful for avoiding antialiasing artifacts.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

continuous.rangeRound( [range] )

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

  • [range]: It is an array that contains the range for the domain specified.

Return Values: This function does not return anything.



Below programs illustrate the continuous.rangeRound() function in D3.js:

Example 1:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content=
        "width=device-width,initial-scale=1.0"/>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h2 style="color: green;">Geeksforgeeks</h2>
  
    <p>continuous.rangeRound() Function </p>
  
    <script>
        var continuous = d3.scaleLinear()
            // Domain ranges -10, 0, 10
            .domain([-10, 0, 10])
            // Range for the domain
            .rangeRound([10, 20, 30, 40, 
                    50, 60, 70, 80, 90]);
  
        document.write("<br/><div>");
        document.write("<p> With rangeRound()");
        document.write("<h3>" + continuous(10) + "</h3>");
        document.write("<h3>" + continuous(2) + "</h3>");
        document.write("<h3>" + continuous(11.5) + "</h3>");
        document.write("<h3>" + continuous(-1) + "</h3>");
        document.write("<h3>" + continuous(1.15) + "</h3>");
        document.write("<h3>" + continuous(5) + "</h3></div>");
  
        var continuous = d3.scaleLinear()
  
            // Domain ranges -10, 0, 10
            .domain([-10, 0, 10])
            // Range for the domain
            .range([10, 20, 30, 40, 50, 60, 70, 80, 90])
  
        document.write("<br/><div>");
        document.write("<p> Without rangeRound()");
        document.write("<h3>" + continuous(10) + "</h3>");
        document.write("<h3>" + continuous(2) + "</h3>");
        document.write("<h3>" + continuous(11.5) + "</h3>");
        document.write("<h3>" + continuous(-1) + "</h3>");
        document.write("<h3>" + continuous(1.15) + "</h3>");
        document.write("<h3>" + continuous(5) + "</h3></div>");
    </script>
</body>
  
</html>

Output:

Example 2:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, 
                   initial-scale=1.0" />
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    </script>
    <script src=
    </script>
    <script src=
    </script>
  
    <style>
        div {
            line-height: 15px;
            float: left;
            padding: 10px;
            word-wrap: break-word;
            margin-left: 10px;
            height: 200px;
            width: 300px;
        }
    </style>
</head>
  
<body>
    <h2 style="color:green;">Geeks for geeks</h2>
  
    <p>continuous.rangeRound() Function </p>
  
    <script>
        var continuous = d3.scaleLinear()
            // Domain ranges -10, 0, 10
            .domain([-10, 0, 10])
            // Range for the domain
            .range([10, 20, 30, 40, 50, 60, 70, 80, 90])
            .interpolate(d3.interpolateRound);
  
        document.write("<br/><div>");
        document.write(
            "<p> With range().interpolate(d3.interpolate.Round)");
        document.write("<h3>" + continuous(10) + "</h3>");
        document.write("<h3>" + continuous(2) + "</h3>");
        document.write("<h3>" + continuous(11.5) + "</h3>");
        document.write("<h3>" + continuous(-1) + "</h3>");
        document.write("<h3>" + continuous(1.15) + "</h3>");
        document.write("<h3>" + continuous(5) + "</h3></div>");
  
        var continuous = d3.scaleLinear()
            // Domain ranges -10, 0, 10
            .domain([-10, 0, 10])
            // Range for the domain
            .rangeRound([10, 20, 30, 40, 50, 60, 70, 80, 90])
  
        document.write("<br/><div>");
        document.write("<p> With rangeRound()");
        document.write("<h3>" + continuous(10) + "</h3>");
        document.write("<h3>" + continuous(2) + "</h3>");
        document.write("<h3>" + continuous(11.5) + "</h3>");
        document.write("<h3>" + continuous(-1) + "</h3>");
        document.write("<h3>" + continuous(1.15) + "</h3>");
        document.write("<h3>" + continuous(5) + "</h3></div>");
    </script>
</body>
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :