Reputation: 413
I was wondering if anyone knew of any way to setting a bar colour to a certain colour based on a certain condition. So, for instance, say the value passes a certain predefined threshold, then that bar would change colour to red to indicate that it needed attention. Anyone have any clue how this would be done, or if it even can be done?
Upvotes: 1
Views: 576
Reputation: 413
Doesn't matter, figured it out.
chart
.colorAccessor(function (d) {
if (d.value > 12) {
return "test1";
}
if (d.value > 9) {
return "test2";
}
if (d.value > 6) {
return "test3";
}
if (d.value > 3) {
return "test4";
}
})
.colors(d3.scale.ordinal().domain(["test1", "test2", "test3", "test4"])
.range(["red", "orange", "yellow", "green"]))
So you can have as many different value thresholds as you want, and a different colour for each threshold.
Upvotes: 2