我将barChart的颜色方案定义如下:
var colorChoice = d3.scale.ordinal().domain(["negative","positive","test"])
.range(["#FF0000","#00FF00","#FFFF00"]);
myBarChart
.colors(colorChoice)
.colorAccessor(function(d) {
if (+d.data.value>0) {
console.log("positive");
return("positive");
} else {
console.log("negative");
return("negative");
}
});
但是当我renderAll()
时,所有条形都是我colorChoice.domain()
的第一项的颜色(所以在这种情况下#FF0000
)会发生什么。
我尝试在域中切换两个第一个值,它始终是第一个使用的值。
我还验证了我的colorAccessor
函数输出的值应该由`colorChoice正确解释。 (参见下面的控制台日志)
3 negative metrics:319
3 positive metrics:316
negative metrics:319
3 positive metrics:316
negative metrics:319
positive metrics:316
2 negative metrics:319
positive metrics:316
欢迎所有帮助。