Skip to content
Related Articles
Open in App
Not now

Related Articles

D3.js | d3.quantile() Function

Improve Article
Save Article
  • Last Updated : 28 Jun, 2019
Improve Article
Save Article

The d3.quantile() function in D3.js is used to returns the p-quantile of the given sorted array of elements. Where p is the number lies in the range[0, 1].

Syntax:

d3.quantile(Array, p)

Parameters: This function accept two parameters as mentioned above and described below:

  • Array: It holds the sorted array of elements.
  • p: It is the p-quantile which are returned over the given sorted array of elements.

Return Value: It returns the p-quantile of the given sorted array of elements.

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

Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <title>
        d3.quantile() function
    </title>
      
    <script src = "https://d3js.org/d3.v4.min.js"></script>
</head>
  
<body>
    <script>
      
        // Initialising a array    
        var Array = [10, 20, 30, 40, 50];
          
        // Calling the d3.quantile() function
        A = d3.quantile(Array, 0); 
        B = d3.quantile(Array, 0.25); 
        C = d3.quantile(Array, 0.5);
        D = d3.quantile(Array, 0.75); 
        E = d3.quantile(Array, 1);
           
        // Getting the shuffled elements
        document.write(A + "<br>");
        document.write(B + "<br>");
        document.write(C + "<br>");
        document.write(D + "<br>");
        document.write(E + "<br>");
    </script>
</body>
  
</html>                    

Output:

10
20
30
40
50

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <title>
        d3.quantile() function
    </title>
      
    <script src = "https://d3js.org/d3.v4.min.js"></script>
</head>
  
<body>
    <script>
      
        // Initialising an array    
        var Array = [10, 20, 30];
          
        // Calling the d3.quantile() function
        A = d3.quantile(Array, 0); 
        B = d3.quantile(Array, 0.25); 
        C = d3.quantile(Array, 0.5);
        D = d3.quantile(Array, 0.75); 
        E = d3.quantile(Array, 1);
           
        // Getting the shuffled elements
        document.write(A + "<br>");
        document.write(B + "<br>");
        document.write(C + "<br>");
        document.write(D + "<br>");
        document.write(E + "<br>");
    </script>
</body>
  
</html>                    

Output:

10
15
20
25
30

Reference: https://devdocs.io/d3~5/d3-array#quantile


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!