Thursday, October 23, 2025
HomeLanguagesJavascriptD3.js scaleQuantile() Function

D3.js scaleQuantile() Function

The d3.scaleQuantile() function in D3.js is used to create and return a new quantile scale that has the specified domain and range. In case the domain or the range is not specified, each value is set to empty array by default.

Syntax:

d3.scaleQuantile( domain, range )

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

  • domain: It is an array of only integers that defines the extent of domain values. It is an optional parameter. The default value is set to empty array.
  • range: It is an array of integers or strings. It is an optional parameter. The default value is set to empty array.

Return Values: This function does not return anything.

Below programs illustrate the d3.scaleQuantile() function in D3.js:

Example 1:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <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>
    <h1 style="color: green;">neveropen</h1>
  
    <p>d3.ScaleQuantile() Function </p>
  
    <script>
        // Using scaleQuantile function
        var quantile = d3.scaleQuantile()
            .domain([0, 1])
            .range(["blue", "yellow", "green"]);
  
        document.write("<h3>" +
            quantile(0) + "</h3>");
        document.write("<h3>" +
            quantile(0.3) + "</h3>");
        document.write("<h3>" +
            quantile(0.5) + "</h3>");
        document.write("<h3>" +
            quantile(0.9) + "</h3>");
    </script>
</body>
  
</html>


Output:

Example 2:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <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>
    <h1 style="color: green;">
        neveropen
    </h1>
  
    <p>d3.ScaleQuantile() Function </p>
  
    <script>
        // Using the scaleQuantile function
        var quantile = d3.scaleQuantile()
            .domain([0, 1])
            .range([1, 100]);
  
        document.write("<h3>" +
            quantile(0) + "</h3>");
        document.write("<h3>" +
            quantile(0.3) + "</h3>");
        document.write("<h3>" +
            quantile(0.5) + "</h3>");
        document.write("<h3>" +
            quantile(0.9) + "</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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS