D3.js | color.toString() Function
The color.toString() function in D3.js is used to return a string representing the color according to the CSS Object Model specification. Syntax:
color.toString()
Parameters: This function does not accept any parameters. Return Value: This function returns a string representing the color according to the CSS Object Model specification. Below programs illustrate the color.toString() function in D3.js: Example 1:
javascript
<!DOCTYPE html>
<html>
<head>
<title>color.toString() function </title>
</head>
<body>
<script>
var color1 = d3.color("red");
var color2 = d3.color("green");
var color3 = d3.color("blue");
var A = color1.toString();
var B = color2.toString();
var C = color3.toString();
console.log(A);
console.log(B);
console.log(C);
</script>
</body>
</html>
|
Output:
rgb(255, 0, 0)
rgb(0, 128, 0)
rgb(0, 0, 255)
Example 2:
javascript
<!DOCTYPE html>
<html>
<head>
<title>color.toString() function </title>
</head>
<body>
<script>
var color = d3.rgb();
var A = color.toString();
console.log(A);
</script>
</body>
</html>
|
Output:
rgb(0, 0, 0)
Reference: https://devdocs.io/d3~5/d3-color#color_toString
Last Updated :
31 Mar, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...