Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavascriptD3.js d3.quantile() Function

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:

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

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

Recent Comments