echarts柱状图颜色渐变和柱形效果实现

 option = {
   tooltip: {
     trigger: 'axis',
     axisPointer: {
       type: 'shadow',
       textStyle: {
         color: '#fff',
       },
     },
   },
   dataset: {
     source: apiData,
     dimensions: ["region", "djl"]
   },
   grid: {
     borderWidth: 0,
     top: 40,
     bottom: 50,
     left: 50,
     right: 30,
     textStyle: {
       color: '#fff',
     },
     lineStyle: {
       color: 'rgba(0,30,40,0.4)',
     },
   },
   calculable: true,
   xAxis: [{
     type: 'category',
     axisLine: {
       lineStyle: {
         color: 'rgba(120,150,150,0.5)',
       },
     },
     splitLine: {
       show: false,
     },
     axisTick: {
       show: false,
     },
     splitArea: {
       show: false,
     },
     axisLabel: {
       interval: 0,
       color: '#88cbfe',
       fontSize: 14,
       formatter: function(value) {
         if (value.length > 4 && value.length <= 8) {
           return value.substr(0, 4) + '\n' + value.substr(4, 4)
         } else if (value.length > 8) {
           return value.substr(0, 4) + '\n' + value.substr(4, 4) + '...'
         } else {
           return value
         }
       }
     }
   }, ],
   yAxis: [{
     name: '',
     nameTextStyle: {
       color: 'rgba(136,203,254,0.5)',
       padding: [0, 0, 0, -50],
     },
     nameGap: 15,
     type: 'value',
     splitLine: {
       show: true,
       lineStyle: {
         type: 'solid',
         color: 'rgba(100,100,120,0.2)',
       },
     },
     min: 0,
     axisLine: {
       show: false,
     },
     axisTick: {
       show: false,
     },
     axisLabel: {
       show: true,
       interval: 0,
       color: 'rgba(136,203,254,0.5)',
       fontSize: 12,
       formatter: '{value}%',
     },
     splitArea: {
       show: false,
     },
   }],
   series: [{
       name: '柱顶部',
       type: 'pictorialBar',
       symbolSize: [15, 9],
       symbolOffset: [0, -5],
       z: 12,
       tooltip: {
         show: false
       },
       itemStyle: {
         normal: {
           color: function(params) {

             let ty = Number(params.data.djl);


             if (0 < ty && ty < 90) {
               return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                   offset: 0,
                   color: "rgba(213,79,26,1)"
                 },
                 {
                   offset: 1,
                   color: "rgba(213,79,26,1)"
                 }
               ])
             } else if (90 < ty && ty < 95) {
               return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                   offset: 0,
                   color: "rgba(162,127,22,1)"
                 },
                 {
                   offset: 1,
                   color: "rgba(162,127,22,1)"
                 }
               ])
             } else if (95 <= ty && ty < 100) {
               return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                   offset: 0,
                   color: "rgba(47,136,229,1)"
                 },
                 {
                   offset: 1,
                   color: "rgba(47,136,229,1)"
                 }
               ])
             }
           }
         },
       },
       label: {
         show: false,
         position: 'top',
         fontSize: 16,
       },
       symbolPosition: 'end',
       data: apiData.djl,
     },
     {
       name: '柱底部',
       type: 'pictorialBar',
       symbolSize: [15, 9],
       symbolOffset: [0, 0],
       z: 12,
       tooltip: {
         show: false
       },
       itemStyle: {
         normal: {
           color: function(params) {

             let ty = Number(params.data.djl);


             if (0 < ty && ty < 90) {
               return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                   offset: 0,
                   color: "rgba(213, 79, 26, 0.15)"
                 },
                 {
                   offset: 1,
                   color: "rgba(213, 79, 26, 0.15)"
                 }
               ])
             } else if (90 < ty && ty < 95) {
               return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                   offset: 0,
                   color: "rgba(162, 127, 22, 0.2)"
                 },
                 {
                   offset: 1,
                   color: "rgba(162, 127, 22, 0.2)"
                 }
               ])
             } else if (95 <= ty && ty < 100) {
               return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                   offset: 0,
                   color: "rgba(47, 136, 229, 0.2)"
                 },
                 {
                   offset: 1,
                   color: "rgba(47, 136, 229, 0.2)"
                 }
               ])
             }
           }
         },
       },
       data: apiData.djl,
     },
     {
       name: '设备登记率(%)',
       type: 'bar',
       barMaxWidth: 15,
       barGap: '10%',
       itemStyle: {
         normal: {
           color: function(params) {

             let ty = Number(params.data.djl);


             if (0 < ty && ty < 90) {
               return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                   offset: 0,
                   color: "rgba(213,79,26,0.8)"
                 },
                 {
                   offset: 1,
                   color: "rgba(213, 79, 26, 0.15)"
                 }
               ])
             } else if (90 < ty && ty < 95) {
               return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                   offset: 0,
                   color: "rgba(162,127,22,0.8)"
                 },
                 {
                   offset: 1,
                   color: "rgba(162, 127, 22, 0.2)"
                 }
               ])
             } else if (95 <= ty && ty < 100) {
               return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                   offset: 0,
                   color: "rgba(47,136,229,0.8)"
                 },
                 {
                   offset: 1,
                   color: "rgba(47, 136, 229, 0.2)"
                 }
               ])
             }
           }
         }
       },
       label: {
         normal: {
           show: false,
           position: 'top',
           fontSize: 14,
           color: '#ffffff',
           offset: [0, -10],
           fontFamily: 'MicrosoftYaHei'
         },
       },
       encode: {
         x: "tupe",
         y: "djl"
       }
     },

   ],
 }

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值