条形图支柱上没有不同的颜色
Not getting the different color on bar chart pillars
我正在使用 jqplot 编写条形图代码。当我 运行 以下函数时:
问题:三个数据都只显示一个颜色(第一个颜色)
如何为刻度显示不同的颜色?
$(document).ready(function(){
$.jqplot.config.enablePlugins = true;
var d1=${likes[0]};
var d2=${comonelikes[0]};
var d3=${comtwolikes[0]};
var a=[d1,d2,d3];
var ticks = [${myorg},${compOne},${compTwo}];
plot1 = $.jqplot('chart1',[a], {
// Only animate if we're not using excanvas (not in IE 7 or IE 8)..
animate: !$.jqplot.use_excanvas,
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true },
},
seriesColors :[
'#57c1b4','#bd66a9',
'#abb3b6'
],
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks:ticks,
tickOptions: { mark: null,
fontSize: 0
}
},
yaxis: {
min:0,
max:3000000,
tickOptions: {formatString: '%d'},
numberticks:6
}
},
highlighter: { show: true }
});
$('#chart1').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
$('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
}
);
});
有什么解决办法吗?
您需要使用 varyBarColor
渲染器选项告诉绘图以您的颜色绘制条形。
将其添加到您的 seriesDefaults
:
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true },
rendererOptions: {
// Set varyBarColor to true to use the custom colors on the bars.
varyBarColor: true
}
},
这是一个 working jsfiddle example,其中包含您的代码和其他条形颜色。
我正在使用 jqplot 编写条形图代码。当我 运行 以下函数时:
问题:三个数据都只显示一个颜色(第一个颜色) 如何为刻度显示不同的颜色?
$(document).ready(function(){
$.jqplot.config.enablePlugins = true;
var d1=${likes[0]};
var d2=${comonelikes[0]};
var d3=${comtwolikes[0]};
var a=[d1,d2,d3];
var ticks = [${myorg},${compOne},${compTwo}];
plot1 = $.jqplot('chart1',[a], {
// Only animate if we're not using excanvas (not in IE 7 or IE 8)..
animate: !$.jqplot.use_excanvas,
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true },
},
seriesColors :[
'#57c1b4','#bd66a9',
'#abb3b6'
],
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks:ticks,
tickOptions: { mark: null,
fontSize: 0
}
},
yaxis: {
min:0,
max:3000000,
tickOptions: {formatString: '%d'},
numberticks:6
}
},
highlighter: { show: true }
});
$('#chart1').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
$('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
}
);
});
有什么解决办法吗?
您需要使用 varyBarColor
渲染器选项告诉绘图以您的颜色绘制条形。
将其添加到您的 seriesDefaults
:
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true },
rendererOptions: {
// Set varyBarColor to true to use the custom colors on the bars.
varyBarColor: true
}
},
这是一个 working jsfiddle example,其中包含您的代码和其他条形颜色。