Echarts使用技巧

第一次写博客,记录一些在做项目过程中学习到的echarts相关的使用技巧。

 

  1.  柱状图阴影

柱状图阴影有两种实现方式,第一种使用barGap属性设置为'-100%'来实现,第二种使用多坐标轴多图层覆盖实现。以下详细说明:

(1)barGap:

如果只是简单的但一系列的柱状图建议使用,实现简单,官方配置项手册也有说明,查看请点击echarts官方示例,我就不再赘述了。

(2)多坐标轴多图层。

实现效果如图:

这种方式适合柱状图为多个系列,单纯使用barGap是做不出阴影的效果的。我的实现方式是添加一个隐藏的相同的类目轴(我的是y轴,设置不显示),设置三个显示数据系列使用正常的类目轴,三个阴影系列使用隐藏的类目轴,阴影系列在数据系列图层下,options设置代码如下:

options = {
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        }
      },
      legend: {
        data: ['原始', '解析后', '预处理'],
        top: 0,
        itemGap: 20,
        itemWidth: 16,
        itemHeight: 5,
        textStyle: {
          color: 'white'
        }
      },
      grid: {
        top: '30',
        left: '3%',
        right: '20%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: [{
        type: 'value',
        position: 'top',
        axisLine: {
          lineStyle: {
            color: '#084a8e'
          }
        },
        axisTick: {
          show: false
        },
        axisLabel: {
          show: false
        },
        splitLine: {
          show: false
        }
      }],
      yAxis: [{
        type: 'category',
        inverse: true,
        axisLine: {
          lineStyle: {
            color: '#084a8e'
          }
        },
        axisTick: {
          show: false
        },
        axisLabel: {
          fontSize: 14,
          color: '#B3D5EC'
        },
        data: ['5天','10天','15天','20天','25天', '30天']
      }, {
        type: 'category',
        axisLine: {
          show: false
        },
        axisTick: {
          show: false
        },
        axisLabel: {
          show: false
        },
        splitArea: {
          show: false
        },
        splitLine: {
          show: false
        },
        data: ['5天','10天','15天','20天','25天', '30天']
      }],
      series: [
        {
          name: '原始',
          type: 'bar',
          barWidth: 5,
          barGap: 10,
          yAxisIndex: 0,
          data: [18203, 23489, 29034, 104970, 131744, 63023],
          itemStyle: {
            color: '#66CC33',
            barBorderRadius: [0, 5, 5, 0]
          },
          z: 2
        },
        {
          name: '解析后',
          type: 'bar',
          barWidth: 5,
          barGap: 10,
          data: [19325, 23438, 31000, 121594, 134141, 68180],
          itemStyle: {
            color: '#FFCC00',
            barBorderRadius: [0, 5, 5, 0]
          },
          z: 2
        },
        {
          name: '预处理',
          type: 'bar',
          barWidth: 5,
          barGap: 3,
          data: [11111, 22222, 33333, 44444, 55555, 66666],
          itemStyle: {
            color: '#FF6600',
            barBorderRadius: [0, 5, 5, 0]
          },
          z: 2
        },
        {
          name: '原始',
          type: 'bar',
          barWidth: 5,
          barGap: 3,
          yAxisIndex: 1,
          data: [134141, 134141, 134141, 134141, 134141, 134141],
          tooltip: {
            show: false
          },
          itemStyle: {
            color: '#292937',
            barBorderRadius: [0, 5, 5, 0]
          },
          silent: true,
          z: 1
        },
        {
          name: '解析后',
          type: 'bar',
          barWidth: 5,
          barGap: 3,
          yAxisIndex: 1,
          data: [134141, 134141, 134141, 134141, 134141, 134141],
          tooltip: {
            show: false
          },
          itemStyle: {
            color: '#292937',
            barBorderRadius: [0, 5, 5, 0]
          },
          silent: true,
          z: 1
        },
        {
          name: '预处理',
          type: 'bar',
          barWidth: 5,
          barGap: 3,
          yAxisIndex: 1,
          data: [134141, 134141, 134141, 134141, 134141, 134141],
          tooltip: {
            show: false
          },
          itemStyle: {
            color: '#292937',
            barBorderRadius: [0, 5, 5, 0]
          },
          silent: true,
          z: 1
        },
      ]
    }

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值