d3.js v5 version is in use, as follows: javascript code snippet
let colorData = [1, 2, 3, 4, 5, 6, 7, 8];
let colorSchemes = [
d3.scaleOrdinal(d3.schemeCategory10),
d3.scaleOrdinal(d3.schemeAccent),
d3.scaleOrdinal(d3.schemePaired),
d3.scaleOrdinal(d3.schemePastel1),
d3.scaleOrdinal(d3.schemeDark2),
d3.scaleOrdinal(d3.schemeSet1)
];
let scheme = colorSchemes[0];
let test_color = scheme(1); // test_color = -sharp1f77b4
// here ignore some code about "svgs"
svgs.selectAll("circle")
.data(colorData).enter()
.append("circle")
.attr("fill", (d, i) => {
let scheme = colorSchemes[i];
return scheme(d); // the console log "scheme is not a function"
});
Why does test_color
get the value correctly while the same code in the closure does not execute correctly?