在Flot中使用“类别”模式时,每个栏如何使用不同的颜色?
这个代码使每个条形在颜色数组中是第一个颜色.我希望每个栏都是颜色数组中相应的颜色.
当前代码:
var data = [["Red",1],["Yellow",2],["Green",3]]; $.plot("#placeholder1div",[data],{ series: { bars: { show: true,barWidth: 0.3,align: "center",lineWidth: 0,fill:.75 } },xaxis: { mode: "categories",},colors: ["#FF0000","#FFFF00","#00FF00"] });
解决方法
通常我的建议与Flot,放下插件并配置它自己.
// separate your 3 bars into 3 series,color is a series level option var data = [{data: [[0,1]],color: "red"},{data: [[1,2]],color: "yellow"},{data: [[2,3]],color: "green"}]; $.plot("#placeholder",data,xaxis: { // drop the categories plugin and label the ticks yourself // you'll thank me in the long run ticks: [[0,"Red"],[1,"Yellow"],[2,"Green"]] } });
生产(小提琴here):