【发布时间】:2015-07-03 21:48:54
【问题描述】:
我在 stackoverflow 上提出了这个问题: Varying bar colors with morris.js bar chart?
如果B栏中的数据高于或低于70,我想改变它的颜色。
我只是想不通我在这里做错了什么才能让它发挥作用?
这是我的代码:
new Morris.Bar({
element: 'bar-example',
gridTextColor: '#00ff55',
data: [
{ y: '2006', a: 100, b: 90 },
{ y: '2007', a: 75, b: 65 },
{ y: '2008', a: 50, b: 40 },
{ y: '2009', a: 75, b: 65 },
{ y: '2010', a: 50, b: 40 },
{ y: '2011', a: 75, b: 65 },
{ y: '2012', a: 100, b: 90 }
],
barColors : function(row, series, type) {
if(data.b <70) return ['black', 'white'];
else if(data.b >= 70) return ['white', 'black'];
},
xkey: 'y',
ykeys: ['a', 'b'],
labels: ['Series A', 'Series B']
});
【问题讨论】:
-
varColors->barColors?您也可以考虑使用>= 70,以防data.b等于70。还要将#00ff55用引号括起来。 -
我在哪里做了你的建议,但看起来我无法访问数据 b colom?我在玩它:jsbin.com/cekecowiti/edit?html,js,console,output
标签: javascript bar-chart morris.js