echarts制作两个柱状图

let colorList=['#02ce8b','#ffbe62','#f17373'];
let data1 = [90,80,70,50]
option = {
title:[
  
          { // 第一个标题
            text: '环保检测', // 主标题
            textStyle: { // 主标题样式
              color: '#333',
              fontWeight: 'bold',
              fontSize: 16
            },
            left: '20%', // 定位到适合的位置
            top: '10%', // 定位到适合的位置

          },
         { // 第一个标题
            text: '水保三色评价得分表', // 主标题
            textStyle: { // 主标题样式
              color: '#333',
              fontWeight: 'bold',
              fontSize: 16
            },
            left: '70%', // 定位到适合的位置
            top: '10%', // 定位到适合的位置

          },
  ],
  legend: [{
    show:true,
    x:'20%',
    y:'20%',
   
  },
  
],


  tooltip: {},
   grid: [
    { left: '5%', top: '25%', width: '40%', height: '50%' },
    { right: '5%', top: '25%', width: '40%', height: '50%' },
    
  ],
 xAxis: [
    { 
      gridIndex: 0,
      type: 'category',
      data: ['第一季度', '第二季度', '第三季度', '第四季度']
      },
    { 
      gridIndex: 1,
       type: 'category',
      data: ['第一季度', '第二季度', '第三季度', '第四季度']
    },
   
  ],
  yAxis: [
    { 
      gridIndex: 0,  
      type: 'value'
      },
    {
      gridIndex: 1, 
      type: 'value' 
      
    },
    
  ],
  // Declare several bar series, each will be mapped
  // to a column of dataset.source by default.
  series: [
    {
      name: '合格',
      type: 'bar',
      barWidth:20,
      xAxisIndex: 0,
      yAxisIndex: 0,
      stack: 'Ad',
       color:'#02ce8b',
       label: {
                normal: {
                    show: true,
                    position: 'inside',
                    color:'#000000'
                }
            },
      emphasis: {
        focus: 'series'
      },
      data: [11, 9, 7, 6]
    },
    {
      name: '不合格',
      type: 'bar',
      barWidth:20,
      
      xAxisIndex: 0,
      yAxisIndex: 0,
      stack: 'Ad',
      color:'#f17373',
       label: {
                normal: {
                    show: true,
                    position: 'top',
                    color:'#000000'
                }
            },
      emphasis: {
        focus: 'series'
      },
      data: [4, 0, 2, 2]
    },
    
     {

      data: data1,
      type: 'bar',
      xAxisIndex: 1,
      yAxisIndex: 1,
      name:'',
      barWidth:20,
      label: {
          normal: {
                    show: true,
                    position: 'top',
                    color:'#000000'
                },
            show: true,
            formatter: function(params) {
                if (params.data < 20) {
                    return '低';
                } else if (params.data < 40) {
                    return '中';
                } else {
                    return '高';
                }
            }
        },
   
       itemStyle: {    
                    color: (param) => {    
                    let num = param.data; 
                    if (num >= 80) {
                        return colorList[0];
                    }else if(num > 60 && num < 80){
                        return colorList[1];
                    }else if(num < 60){
                       return colorList[2];
                    }
                   
                    }

    }
    }
    
    ]
};

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是程序喵呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值