【echarts】14、echarts+vue2 - 柱状图pictorialBar

前言

基于echarts5.x和vue2实现
记录以便日后查阅

实现效果

在这里插入图片描述

代码实现

<template>
  <div class="chart-wrap">
    <div id="chart11" class="chart" />
  </div>
</template>

<script>
export default {
  name: 'Index',
  data () {
    return {
      chart: null,
      yData: [22, 6.3, 11.2, 3.2, 1.2],
      xData: ['固定投资', '工业增加值', '规上工业产值', '规上利润', '规上税收']
    }
  },
  mounted() {
    this.createChartHandler()
  },
  methods: {
    // 创建图表
    createChartHandler () {
      this.chart = this.$echarts.init(document.getElementById('chart11'))
      this.chart.setOption(this.getChartOption(this.yData, this.xData))
      window.addEventListener('resize', () => {
        setTimeout(() => {
          this.chart.resize()
        })
      })
    },
    // 获取图表配置项
    getChartOption (yData, xData) {
      return {
        tooltip: {
          trigger: 'axis',
          extraCssText: 'color:#fff;background: rgba(0, 38, 118, 0.5);border:none; box-shadow: 0px 0px 8px 1px rgba(0, 145, 255, 0.5);border-radius: 2px;',
          axisPointer: {
            type: 'none'
          },
          formatter: function (params) {
            return params[0].name + ': ' + params[0].value + '亿'
          }
        },
        grid: {
          left: '5%',
          right: '5%',
          bottom: '0',
          top: '10%',
          containLabel: true
        },
        xAxis: {
          data: xData,
          axisTick: {
            show: false
          },
          axisLine: {
            lineStyle: {
              color: 'rgba(42, 109, 251, 0.79)',
              width: 1 // 这里是为了突出显示加上的
            }
          },
          axisLabel: {
            interval: 0,
            rotate: 0,
            color: '#ffffff',
            fontSize: 12
            // formatter (params) {
            //   return formatter(params, wordNum)
            // }
          }
        },
        yAxis: {
          axisTick: {
            show: false
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: 'rgba(42, 109, 251, 0.79)',
              width: 1 // 这里是为了突出显示加上的
            }
          },
          axisLabel: {
            color: '#ffffff',
            fontSize: 12
          },
          splitArea: {
            lineStyle: 'dashed',
            areaStyle: {
              color: 'rgba(255,255,255,.5)'
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: 'rgba(0, 145, 255, 0.29)',
              width: 1,
              type: 'dashed'
            }
          }
        },
        color: ['rgba(6, 200, 140, 0.71)', 'rgba(2, 99, 255, 0.71)', 'rgba(255, 135, 23, 0.71)', 'rgba(252, 211, 31, 0.71)', 'rgba(17, 209, 247, 0.71)'],
        series: [{
          name: 'hill',
          type: 'pictorialBar',
          barCategoryGap: '0%',
          symbolClip: true,
          // symbol: 'path://M0,10 L10,10 L5,0 L0,10 z',
          symbol: 'path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z',
          itemStyle: {
            color: function (params) {
              var colorList = ['rgba(6, 200, 140, 0.71)', 'rgba(2, 99, 255, 0.71)', 'rgba(255, 135, 23, 0.71)', 'rgba(252, 211, 31, 0.71)', 'rgba(17, 209, 247, 0.71)']

              return colorList[params.dataIndex]
            }
          },
          label: {
            show: true,
            position: 'top',
            // offset: [0, 0],
            color: 'inherit',
            formatter: '{c}',
            fontSize: 14
          },
          emphasis: {
            itemStyle: {
              opacity: 1
            }
          },
          data: yData,
          z: 10
        }]
      }
    }
  }
}
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值