【发布时间】:2016-12-04 07:10:16
【问题描述】:
var dots = svg.selectAll(".dot")
.data(data)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 5)
.attr("cx", xDots)
.attr("cy", yDots)
.style("fill", function(d) {
cd = d;
//
if(m.options.hicColors != null ) {
if(d.hic <= m.options.cutoffs[0]) {
d.fillColor = m.options.hicColors[0];
return m.options.hicColors[0];
} else if (d.hic > m.options.cutoffs[0] && d.hic <= m.options.cutoffs[1]) {
d.fillColor = m.options.hicColors[1];
return m.options.hicColors[1];
} else if(d.hic > m.options.cutoffs[1] && d.hic <= m.options.cutoffs[2]){
d.fillColor = m.options.hicColors[2];
return m.options.hicColors[2];
} else if(d.hic > m.options.cutoffs[2] && d.hic <= m.options.cutoffs[3]) {
d.fillColor = m.options.hicColors[3];
return m.options.hicColors[3];
} else {
d.fillColor = m.options.hicColors[4];
return m.options.hicColors[4];
}
}
})
我正在处理的程序涉及采用一组形状并根据两个数组对它们进行着色,一个包含要使用的颜色,另一个包含用于决定使用哪种颜色的截止值。以前,这些总是 5 种颜色和 4 个截止值,但现在我需要接受任意长度的数组。我不知道我怎么能做到这一点。有人对我如何完成这项任务有任何建议吗?
请注意,颜色数组的长度总是比截止数组大一。
【问题讨论】:
-
尝试循环,如果有问题,请告诉我们你做了什么。
-
你为什么不简单地使用秤?
标签: javascript arrays if-statement d3.js