echarts柱状图不同颜色_Echarts 柱状图的每个柱子显示不同颜色问题 及柱子上显示比例...

625c2ff54ef615bd8f880a90159bcdcc.png

d198353a7b3b6fd19a593088ab060cff.png

在itemStyle中添加即可

series: [{
        name: '降水量',
        type: 'bar',
        label: {
            normal: {
                show: true,
                position: 'top'
            }
        },
        itemStyle: {
            normal: {
                // 随机显示
                //color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
              
                // 定制显示(按顺序)
                color: function(params) { 
                    var colorList = ['#C33531','#EFE42A','#64BD3D','#EE9201','#29AAE3', '#B74AE5','#0AAF9F','#E89589','#16A085','#4A235A','#C39BD3 ','#F9E79F','#BA4A00','#ECF0F1','#616A6B','#EAF2F8','#4A235A','#3498DB' ]; 
                    return colorList[params.dataIndex] 
                }
            },
        },
        data: [32.6, 25.9, 39.0, 26.4, 28.7, 70.7, 75.6, 82.2, 48.7, 58.8, 16.0, 32.3],
    }]

或者固定颜色

 yAxis : [
        {
            type : 'value',
            show:false 
        }
    ],
    series : [
        {
            name:'总数量',
            type:'bar',
            barWidth: '60%',
            color: '#338AF6',
            data:[10, 52, 200, 334, 390, 330, 220],
           
            
        }
    ]

增加每个百分比 % :增加代码: formatter: '{c}%',具体如下:

series: [{
          name: '总数量',
          type: 'bar',
          barWidth: '60%',
          itemStyle: {
            normal: {
              // 随机显示
              //color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
              // 定制显示(按顺序)
               color: function(params) {
                 var colorList = ['#338AF6', '#78C77D', '#F4D35F', '#435184', '#8C67DE', '#6BC8CA', '#0AAF9F', '#E89589', '#16A085', '#4A235A', '#C39BD3 ', '#F9E79F', '#BA4A00', '#ECF0F1', '#616A6B', '#EAF2F8', '#4A235A', '#3498DB'];
                  return colorList[params.dataIndex]
                },
              label: {
                    show: true,
                    formatter: '{c}%',
                    position: 'top'
                }
            }
          },
          data: [50, 20, 70, 48, 40, 52]
       }]

d198353a7b3b6fd19a593088ab060cff.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值