The d3.scaleBand() function in D3.js is used to construct a new band scale with the domain specified as an array of values and the range as the minimum and maximum extents of the bands. This function splits the range into n bands where n is the number of values in the domain array.
Syntax:
d3.scaleBand().domain(array of values).range(array of values);
Parameters: This function does not accept any parameters.
Return Value: This function returns the corresponding range for the domain’s value.
Below programs illustrate the d3.scaleBand() function in D3.js:
Example 1:
<!DOCTYPE html> <html> <head> <title> D3.js | d3.scaleBand() Function </title> <script src = </script> </head> <body> <script> // Calling the scaleBand() function var A = d3.scaleBand() .domain(['January', 'February', 'March', 'April', 'May']) .range([10, 50]); // Getting the corresponding range for // the domain value console.log(A('January')); console.log(A('February')); console.log(A('March')); console.log(A('April')); console.log(A('May')); </script> </body> </html> |
Output:
10 18 26 34 42
Example 2:
<!DOCTYPE html> <html> <head> <title> D3.js | d3.scaleBand() Function </title> <script src = </script> </head> <body> <script> // Calling the scaleBand() function var A = d3.scaleBand() .domain(['January', 'February', 'March', 'April', 'May']) .range([1, 2]); // Getting the corresponding range for // the domain value console.log(A('January')); console.log(A('February')); console.log(A('March')); console.log(A('April')); console.log(A('May')); </script> </body> </html> |
Output:
1 1.2 1.4 1.6 1.8
Reference: https://devdocs.io/d3~5/d3-scale#scaleBand
Recommended Posts:
- How to Check a Function is a Generator Function or not using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- p5.js | pow() function
- PHP | pos() Function
- PHP | end() Function
- p5.js | arc() Function
- D3.js zip() Function
- p5.js | abs() function
- p5.js | sq() function
- CSS env() Function
- PHP | max( ) Function
- p5.js | cos() function
- PHP | ord() Function
- p5.js | red() function
- CSS | var() Function
- p5.js | tan() function
- p5.js | sin() function
- p5.js | log() 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.


