D3.js | d3.rgb() Function
The d3.rgb() function in D3.js is used to return RGB value of the specified CSS color.
Syntax:
d3.rgb(color);
Parameters: This function accepts single parameter color which is used to specify the CSS color.
Return Value: This function returns RGB value of the given CSS color.
Below programs illustrate the d3.rgb() function in D3.js:
Example 1:
<!DOCTYPE html> <html> <head> <title>d3.rgb() function</title> </head> <body> <script> // Calling the d3.rgb() function fuction // with some parameters var color1 = d3.rgb("red"); var color2 = d3.rgb("green"); var color3 = d3.rgb("blue"); // Getting the RGB values console.log(color1); console.log(color2); console.log(color3); </script> </body> </html> |
Output:
{"r":255, "g":0, "b":0, "opacity":1}
{"r":0, "g":128, "b":0, "opacity":1}
{"r":0, "g":0, "b":255, "opacity":1}
Example 2:
<!DOCTYPE html> <html> <head> <title>d3.rgb() function</title> </head> <body> <script> // Calling the d3.rgb() function fuction // without any parameters var color = d3.rgb(); // Getting the RGB values console.log(color); </script> </body> </html> |
Output:
{"r":null, "g":null, "b":null, "opacity":1}
Reference: https://devdocs.io/d3~5/d3-color#rgb
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 | Ds\Set first() Function
- D3.js | d3.map.has() Function
- D3.js | d3.map.set() Function
- PHP | exp() Function
- p5.js | tan() function
- PHP | Ds\Set last() Function
- p5.js | hue() function
- p5.js | day() function
- PHP | pow( ) Function
- p5.js | value() Function
- p5.js | pow() function
- PHP | ord() 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.



