D3.js | d3.max() function
The d3.max() function in D3.js is used to returns the maximum value in the given array using natural order. If an array is empty then it returns undefined as output.
Syntax:
d3.max(Array)
Parameters: This function accepts a parameters Array which is an array of elements whose maximum value is to be calculated. Here elements might be integers or any strings.
Return Value: It returns the maximum value.
Below programs illustrate the d3.max() function in D3.js.
Example 1:
<html> <head> <title>Getting maximum value</title> </head> <body> </script> <script> // initialising the array of elements var Array1 = [10, 20, 30, 40, 50, 60]; var Array2 = [1, 2]; var Array3 = [0, 1.5, 6.8]; var Array4 = [.8, .08, .008]; // Calling to d3.max() function A = d3.max(Array1); B = d3.max(Array2); C = d3.max(Array3); D = d3.max(Array4); // Getting maximum value document.write(A + "<br>" ); document.write(B + "<br>" ); document.write(C + "<br>" ); document.write(D + "<br>" ); </script> </body> </html> |
Output:
60 2 6.8 0.8
Example 2:
<html> <head> <title>Getting maximum value</title> </head> <body> </script> <script> // initialising the array of elements var Array1 = []; var Array2 = [ "a" , "b" , "c" ]; var Array3 = [ "A" , "B" , "C" ]; var Array4 = [ "Geek" , "Geeks" , "GeeksforGeeks" ]; // Calling to d3.max() function A = d3.max(Array1); B = d3.max(Array2); C = d3.max(Array3); D = d3.max(Array4); // Getting maximum value document.write(A + "<br>" ); document.write(B + "<br>" ); document.write(C + "<br>" ); document.write(D + "<br>" ); </script> </body> </html> |
Output:
undefined c C GeeksforGeeks
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- PHP | pos() Function
- PHP | key() Function
- D3.js | d3.map.set() Function
- PHP | Ds\Set add() Function
- PHP | end() Function
- p5.js | log() function
- p5.js | sin() function
- p5.js | cos() function
- PHP | Ds\Map xor() Function
- PHP | abs() Function
- p5.js | max() function
- D3.js | d3.hcl() Function
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.