D3.js | d3.hsl() Function
The d3.hsl() function in D3.js is used to construct a new HSL color and returns HSL properties of the specified color taken as the parameter of the function.
Syntax:
d3.hsl(h, s, l, opacity)
or
d3.hsl(color)
Parameters: This function accepts some parameters as mentioned above and described below:
- h: It is used to set the hue value.
- s: It is used to set the saturation value.
- l: It is used to set the lightness value.
- opacity: It is used to set the opacity/transparency.
- color: It is used to set the color name or hex code.
Return Value: This function returns HSL properties of the specified CSS color taken as the parameter of the function.
Below programs illustrate the d3.hsl() function in D3.js:
Example 1:
<!DOCTYPE html> <html> <head> <title> D3.js | d3.hsl() Function </title> <script src= </script> </head> <body> <script> // Calling the d3.hsl() function function // with some parameters var color1 = d3.hsl("red"); var color2 = d3.hsl("green"); var color3 = d3.hsl("blue"); // Getting the HSL properties console.log(color1); console.log(color2); console.log(color3); </script> </body> </html> |
Output:
{"h":0, "s":1, "l":0.5, "opacity":1}
{"h":120, "s":1, "l":0.25098039215686274, "opacity":1}
{"h":240, "s":1, "l":0.5, "opacity":1}
Example 2:
<!DOCTYPE html> <html> <head> <title> D3.js | d3.hsl() Function </title> <script src= </script> </head> <body> <script> // Calling the d3.hsl() function function // without any parameters var color = d3.hsl(); // Getting the HSL values console.log(color); </script> </body> </html> |
Output:
{"h":null, "s":null, "l":null, "opacity":1}
Ref: https://devdocs.io/d3~5/d3-color#hsl
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 | abs() Function
- PHP | max( ) Function
- PHP | pos() Function
- D3.js | d3.map.set() Function
- p5.js | sq() function
- PHP | key() Function
- p5.js | abs() function
- D3.js | d3.set.has() Function
- PHP | min( ) Function
- p5.js | hue() function
- p5.js | value() Function
- p5.js | max() 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.
Improved By : Akanksha_Rai


