echarts-柱形图每两个柱子不同颜色循环

//材价统计柱形图
priceBarOption = {
    title: {
        text: '材价统计',
        // x: 15,
        // y: 15,
        textStyle: {
            fontSize: '14',
            fontWeight: 'normal',
            color: '#333'
        }
    },
    tooltip: {
        trigger: 'item',
        padding: 10,
        axisPointer: { // 坐标轴指示器,坐标轴触发有效
            type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
        },
        formatter: '{b}<br/>{a}:{c}'
    },
    grid: {
        x: 45,
        x2: 25,
        y: 60,
        y2: 40,
        borderWidth: '1',
        borderColor:'#E0EBFF'
    },
    xAxis: [{
        type: 'category',
        // name: '价格',
        nameTextStyle: {
            color: '#999'
        },
        splitLine: false,
        axisLabel: {
            textStyle: {
                color: '#999'
            }
        },
        axisTick: {
            show:true,
            lineStyle: {
                width: 2,
                color: '#999'
            }
        },
        axisLine: {
            textStyle: {
                color: '#999'
            },
            lineStyle: {
                width: 2,
                color: '#999'
            }
        },
        data: function () {
            var list = [];
            for (var i = 1;i<=12;i++){
                list.push(i + "月");
            }
            return list;
        }()
    }],
    yAxis: [{
        type: 'value',
        // name: '工时',
        nameTextStyle: {
            color: '#999'
        },
        splitLine: {
            lineStyle: {
                color: ['#E0EBFF'],
                width: 1
            }
        },
        splitArea:{    //背景区域分隔
            show:true
        },
        axisLine: {
            lineStyle: {
                width: 2,
                color: '#999'
            }
        },
        axisLabel: {
            textStyle: {
                color: '#999'
            }
        },
        axisTick: {
            show: false
        }
    }],
    series: [{
        name: '工时',
        type: 'bar',
        itemStyle: {
            normal: {
                barBorderRadius: [8, 8, 2, 2],
                barBorderColor: 'rgba(0,0,0,0)',
                areaStyle: {
                    type: 'default'
                },
                //每个柱子的颜色为一组,循环
                color: function(params) {
                        var colorItem = ['#C1232B','#B5C334'];
                        var currentItem=0;
                        var colorList=[];
                    for(var i=0;i<params.series.data.length;i++){
                        colorList.push(colorItem[currentItem]);
                        if(currentItem==0){
                            currentItem=1;
                        }
                        else {
                            currentItem=0;
                        }
                    }
                    return colorList[params.dataIndex]
                }
            },
            emphasis: {     //鼠标悬停时
                barBorderRadius: [8, 8, 2, 2]
            }
        },
        barMaxWidth: 15,
        data: [200,350,460,1500,2000,1800,1300,800,900,1000,1100,700,600]
    }]
};
附图:
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值