Thursday, September 4, 2025
HomeLanguagesJavascriptD3.js quantile.range() Function

D3.js quantile.range() Function

The quantile.range() function is used to set the range for the quantile scale. The number of values in the range array determines the number of quantiles that are created by this function.

Syntax:

quantile.range([range]);

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

  • range: This parameter accepts an array of discrete values.

Return Value: This function does not return any value.

Below examples illustrate the quantile.range() function in D3.js:

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>
</head>
  
<body>
    <h2 style="color:green">GeekforGeeks</h2>
  
    <p>quantile.range() Function</p>
  
    <script>
        var quantile = d3.scaleQuantile()
            .range([6, 12, 18, 24]);
  
        // Printing the output
        document.write("when domain is not specified")
        document.write("<h3>quantile(10): " 
                + quantile(10) + "</h3>");
        document.write("<h3>quantile(20): " 
                + quantile(20) + "</h3>");
    </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>
</head>
  
<body>
    <h2 style="color:green">GeekforGeeks</h2>
    <h3>quantile.range() Function</h3>
    <script>
        var quantile = d3.scaleQuantile()
            // Setting domain for the scale.
            .domain([10, 20, 30, 40])
            // Discrete range
            .range([6, 12, 18, 24]);
  
        // Printing the output
        document.write("<span>quantile(10): " 
            + quantile(10) + "</span><br>");
        document.write("<span>quantile(20): " 
            + quantile(20) + "</span><br>");
        document.write("<span>quantile(30): " 
            + quantile(30) + "</span><br>");
        document.write("<span>quantile(40): " 
            + quantile(40) + "</span><br>");
    </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
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS