Open In App

D3.js d3.quantile() Function

Last Updated : 23 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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:

HTML




<script src="https://d3js.org/d3.v4.min.js"></script>
  
<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
    console.log(A);
    console.log(B);
    console.log(C);
    console.log(D);
    console.log(E);
</script>


Output:

10
20
30
40
50

Example 2:

HTML




<script src="https://d3js.org/d3.v4.min.js"></script>
  
<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
    console.log(A);
    console.log(B);
    console.log(C);
    console.log(D);
    console.log(E);
</script>          


Output:

10
15
20
25
30

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads