D3.js interpolateYlGn() Function
Last Updated :
13 Aug, 2020
The d3.interpolateYlGn() function in D3.js is used to return a particular color from the YlGn sequential color scheme which is returned as an RGB string.
Syntax:
d3.interpolateYlGn(t)
Parameters: This function accepts a single parameter as mentioned above and described below:
- t: “t” is a number in a range [0,1]
Return Values: It returns an RGB string.
Below given are a few examples of the function given above.
Example1:
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" />
< meta
name = "viewport"
path1tent=" width = device -width,
initial-scale = 1 .0"/>
< title >D3.js interpolateYlGn() Function</ title >
</ head >
< style ></ style >
< body >
< script src =
</ script >
< script src =
</ script >
< script src =
</ script >
< script src =
</ script >
< script >
console.log(d3.interpolateYlGn(0));
console.log(d3.interpolateYlGn(0.1));
console.log(d3.interpolateYlGn(0.001));
console.log(d3.interpolateYlGn(0.2));
console.log(d3.interpolateYlGn(0.211));
console.log(d3.interpolateYlGn(0.3));
console.log(d3.interpolateYlGn(1));
</ script >
</ body >
</ html >
|
Output:
Example 2:
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" />
< meta
name = "viewport"
content=" width = device -width,
initial-scale = 1 .0"/>
< title >Document</ title >
</ head >
< style >
div {
padding: 10px;
width: fit-content;
height: 100px;
}
</ style >
< body >
D3.interpolateYlGn()
< div class = "b1" >
< span >
D3.interpolateYlGn(0.9)
</ span >
</ div >
< div class = "b2" >
< span >
D3.interpolateYlGn(0.1)
</ span >
</ div >
< script src =
</ script >
< script src =
</ script >
< script src =
</ script >
< script src =
</ script >
< script >
// Array of colors is given
let color1 = d3.interpolateYlGn(0.9);
let color2 = d3.interpolateYlGn(0.2);
let b1 = document.querySelector(".b1");
let b2 = document.querySelector(".b2");
b1.style.backgroundColor = color1;
b2.style.backgroundColor = color2;
</ script >
</ body >
</ html >
|
Output:
Share your thoughts in the comments
Please Login to comment...