D3.js interpolate.Array() Function
d3.InterpolateArray() is used to interpolate the two arrays and returns an interpolator between them.
Syntax:
d3.interpolateArray(a, b);
Parameters: It takes the two parameters.
- a: It is an Array.
- b: It is an Array.
Returns: It returns the Interpolator function.
Below given are a few Examples of InterpolateArray() function.
Example 1:
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 > </ style > < body > <!--fetching from CDN of D3.js --> < script type = "text/javascript" src = "https://d3js.org/d3.v4.min.js"> </ script > < script > console.log("Type of the function is: ", typeof(d3.interpolateArray([12, 3], [4, 5, 6]))) console.log(d3.interpolateArray([12, 3], [4, 5, 6])(0.2)) console.log(d3.interpolateArray([12, 3], [4, 5, 6])(0.6)) console.log(d3.interpolateArray([12, 3], [4, 5, 6])(0.2)) </ script > </ body > </ html > |
Output:
Example 2:
When the elements of them are other than a number.
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 > </ style > < body > <!--fetching from CDN of D3.js --> < script type = "text/javascript" src = "https://d3js.org/d3.v4.min.js"> </ script > < script > console.log("Type of the function is: ", typeof(d3.interpolateArray([12, 3], [4, 5, 6]))) console.log( d3.interpolateArray([12.25, 3.36], [0.54, 5, .636])(0.2)); // This will give error as it is not an array try{ console.log(d3.interpolateArray(1452, 63244)(0.6)) } catch(err){ console.log(err) } console.log( d3.interpolateArray(["a", "b", "d"], ["a", "c"])(0.2)); </ script > </ body > </ html > |
Output: