echarts 柱状图自定义各个柱子颜色

echarts yekong

wanjunshijiecom 2021-08-20 at 11.11.39@2x

{
            name: '柱状图',
            type: 'bar',
            barWidth: 10,
            zlevel: 2,
            itemStyle: {
              normal: {
                color: function (params) {
                  var list = ['rgba(0, 204, 255, 1)',
                    'rgba(39, 120, 255, 1)',
                    'rgba(72, 176, 255, 1)',
                    'rgba(91, 207, 255, 1)',
                    'rgba(108, 227, 255, 1)',
                    'rgba(119, 240, 240, 1)',
                    'rgba(129, 163, 243, 1)',
                    'rgba(243, 170, 104, 1)',
                    'rgba(245, 232, 140, 1)',
                    'rgba(162, 143, 218, 1)',
                    'rgba(162, 238, 250, 1)',
                    'rgba(38, 116, 255, 1)',
                    'rgba(73, 177, 255, 1)',
                  ]
                  var list2 = ['rgba(0, 204, 255, 0)',
                    'rgba(39, 120, 255, 0)',
                    'rgba(72, 176, 255, 0)',
                    'rgba(91, 207, 255, 0)',
                    'rgba(108, 227, 255, 0)',
                    'rgba(119, 240, 240, 0)',
                    'rgba(129, 163, 243, 0)',
                    'rgba(243, 170, 104, 0)',
                    'rgba(245, 232, 140, 0)',
                    'rgba(162, 143, 218, 0)',
                    'rgba(162, 238, 250, 0)',
                    'rgba(38, 116, 255, 0)',
                    'rgba(73, 177, 255, 0)'
                  ]
                  return new that.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: list[params.dataIndex]
                  }, {
                    offset: 1,
                    color: list2[params.dataIndex]
                  }], false)
                }
              }
            },
            label: {
              normal: {
                show: false,
                fontSize: 18,
                fontWeight: 'bold',
                color: '#ffffff',
                position: 'top',
              }
            },
            data: [254, 3254, 1654, 2454, 4757, 2011, 1211, 3254, 1654, 2454, 4757, 2011, 2011]
          },
喜欢