D3.js | color.rgb() Function
Last Updated :
17 Aug, 2020
The color.rgb() function in D3.js is used to return the RGB equivalent of the specified color.
Syntax:
color.rgb()
Parameters: This function does not accept any parameters.
Return Value: This function returns the RGB equivalent of the specified color.
Below programs illustrate the color.rgb() function in D3.js:
Example 1:
<!DOCTYPE html>
<html>
<head>
<title>color.rgb() function </title>
</head>
<body>
<script>
var color1 = d3.color( "red" );
var color2 = d3.color( "green" );
var color3 = d3.color( "blue" );
var A = color1.rgb();
var B = color2.rgb();
var C = color3.rgb();
console.log(A);
console.log(B);
console.log(C);
</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>color.rgb() function </title>
</head>
<body>
<script>
var color1 = d3.rgb();
var A = color1.rgb();
console.log(A);
</script>
</body>
</html>
|
Output:
{"r":null, "g":null, "b":null, "opacity":1}
Reference: https://devdocs.io/d3~5/d3-color#color_rgb
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...