javascript – 不同颜色的酒吧用于Flot类别条形图

在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):

相关文章

kindeditor4.x代码高亮功能默认使用的是prettify插件,prett...
这一篇我将介绍如何让kindeditor4.x整合SyntaxHighlighter代...
js如何实现弹出form提交表单?(图文+视频)
js怎么获取复选框选中的值
js如何实现倒计时跳转页面
如何用js控制图片放大缩小