Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptD3.js continuous.rangeRound() Function

D3.js continuous.rangeRound() Function

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:

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 src="https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h2 style="color: green;">Geeksforneveropen</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 src="https://d3js.org/d3-color.v1.min.js">
    </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 neveropen</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:

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

Recent Comments