D3.js | d3.quantile() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                    

chevron_right


Output:

10
20
30
40
50

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                    

chevron_right


Output:

10
15
20
25
30

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.