echarts 实现柱状图渐变色

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>2019</title>
</style>
</head>
<body>
<div id="main" style="width: 100%;height: 600px;"></div>

<script>

var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
      xAxis: {
                type: 'value',
                splitLine:{
            show:false
        },
        axisTick: {
          show: false,  
        },
        axisLine:{
            show: false,
            lineStyle:{
            color:'transparent',
            }
        },
                boundaryGap: [0, 0.01],
      },
      yAxis: {
          type: 'category',
          splitLine:{
            show:false
        },
        axisTick: {
          show: false,  
        },
          axisLabel:{
              margin:5,
              fontWeight: 'bold',
              fontSize: 15,
          interval: 0,// 横轴信息全部显示
          rotate: 0 // 0度角倾斜显示
                },
                axisLine:{
                    show: false,
            lineStyle:{
              color:'#FFFFFF',
            }
       },
                 data:['隔壁泰山','夜空中最亮的星夜空中最亮的星','串烧','说学逗唱','猴子说','创意走秀','兔耳朵舞','咖喱咖喱+我爱你']
      },
      series: [{
          name: '评论量(QTY)',
          type: 'bar',
          data: [55,77,88,99,11,22,33,44],
          barWidth:30,
          itemStyle: {
            normal: {
                                barBorderRadius: [0, 5, 5, 0],
                            color: function (params){
                  var colorList = [
                      ['#14c3a2','#14c3a2','#22e8c3','#22e8c3'],
                      ['#07b8d9','#62c4db','#86e9fc','#22e8c3'],
                      ['#0679e3','#3d97ed','#90c1fc','#22e8c3'],
                      ['#07b8d9','#62c4db','#86e9fc','#22e8c3'],
                      ['#0679e3','#3d97ed','#90c1fc','#22e8c3'],
                      ['#07b8d9','#62c4db','#86e9fc','#22e8c3'],
                      ['#0679e3','#3d97ed','#90c1fc','#22e8c3'],
                      ['#07b8d9','#62c4db','#86e9fc','#22e8c3']
                  ];
                  var index = params.dataIndex;
                  if(params.dataIndex >= colorList.length) {
                      index = params.dataIndex - colorList.length;
                  }
                  return new echarts.graphic.LinearGradient(0,0,0,1, [
                      {offset: 0, color: colorList[index][0]},
                      {offset: 0.3, color: colorList[index][1]},
                      {offset: 0.6, color: colorList[index][2]},
                      {offset: 1, color: colorList[index][3]}
                  ]);
              },
                            label: {
                                show: true,
                                position: 'insideLeft',
                                distance: 20,
                                textStyle: {
                                    color: '#ffffff',
                                    fontSize: '16'
                                }
                            }
            },
                        
          },
      }]
    };
console.log(option.yAxis.data);
// 使用刚指定的配置项和数据显示图表。
if (option && typeof option === "object") {
    myChart.setOption(option, true);
}

</script>
</body>
</html>

 

转载于:https://www.cnblogs.com/quietxin/p/10557601.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值