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


    前言

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

    实现效果

    在这里插入图片描述

    代码实现

    <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>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
  • 相关阅读:
    vue项目打包,使用externals抽离公共的第三方库
    IntelliJ Plugin开发 (一) 创建一个编辑器上的右键菜单
    js 一分钟学会使用闭包
    leetcode路飞吃桃,递归做法
    MFC界面美化之自绘按钮控件的实现,圆角按钮,图片按钮
    CentOS 7下yum安装GitLab CE
    MySQL允许root远程登录
    Docker build创建指定容器镜像
    Vue2基础
    Python之写文件操作(二十九)
  • 原文地址:https://blog.csdn.net/weixin_44402694/article/details/126016359