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