echarts 进度条类型柱状图

父组件:
javascript 复制代码
<barChartProfit :opt="avgProfit" />

import barChartProfit from "./components/barChartProfit";

data() {
	return {
		avgProfit: {
	        xData: ['2019', '2020', '2021', '2022', '2023'],
	        totalData: [30,30,30,30,30],
	        seriesData: [10,11,12,21,15]
	      }
	}
}
子组件:
javascript 复制代码
<template>
  <div style="width: 100%;height: 100%;">
    <ChartPanel ref="chart" :option="options" :style="opt.yAxisName ? 'height:calc(100% - 16px)' : ''"></ChartPanel>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import ChartPanel from '@/components/ChartPanel';
export default {
  components: {
    ChartPanel
  },
  props: {
    opt: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      options: null
    }
  },
  watch: {
    opt: {
      deep: true,
      immediate: true,
      handler(val) {
        // if (val && val.seriesData) {
        this.getOpt(val)
        // }
      }
    }
  },
  methods: {
    getOpt(val) {
      let {
        seriesData,
        xData,
        totalData
      } = val
      this.options =  {
        title: {
          text: '年人均利润',
          x: 'left',
          y: 0,
          textStyle: {
            color: 'rgba(35, 35, 56, 1)',
            fontSize: 16,
            fontWeight: '700',
          },
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          },
          formatter: params => {
            let i = params.length - 1
            let result = `
            <div>${params[i].name}年
              <span style="color:#336CFF;font-weight:700">${params[i].value}万元</span>  
            </div>`
            return result
          }
        },
        xAxis: {
          type: 'value',
          max: totalData[0],
          axisLabel: {
            show: true,
            textStyle: {
              color: "#595D64",
              fontSize: 14,
            }
          },
          splitLine: {
            show: false,
          }
        },
        grid: {
          left: '40',
          right: '16',
          bottom: '0',
          top: 32,
          containLabel: true
        },
        yAxis: [{
          type: "category",
          inverse: false,
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            show: false
          },
          data: xData,
        }],
        series: [{
          // 灰色背景
          type: "bar",
          barWidth: 12,
          legendHoverLink: false,
          silent: true,
          itemStyle: {
            normal: {
              color: 'rgba(242, 244, 247, 1)',
            }
          },
          label: {
            normal: {
              show: true,
              position: "left",
              formatter: "{b}",
              textStyle: {
                color: "rgba(89, 93, 100, 1)",
                fontSize: 14,
              }
            }
          },
          data: totalData,
          z: 1,
          animationEasing: "elasticOut"
        },
        {
          // 灰色背景分隔线
          type: "pictorialBar",
          itemStyle: {
            normal: {
              color: "#fff"
            }
          },
          symbolRepeat: "fixed",
          symbolMargin: 4,
          symbol: "rect",
          symbolClip: true,
          symbolSize: [2, 14],
          symbolPosition: "start",
          symbolOffset: [1, -1],
          data: totalData,
          z: 2,
          animationEasing: "elasticOut"
        }, {
          // 蓝色背景
          type: "bar",
          barWidth: 12,
          barGap: '-100%',
          legendHoverLink: false,
          silent: true,
          itemStyle: {
            normal: {
              color: 'rgba(53, 98, 212, 1)',
            }
          },
          label: {
            normal: {
              show: true,
              position: "right",
              formatter: "{c}万元",
              textStyle: {
                color: "#595D64",
                fontSize: 14
              }
            }
          },
          data: seriesData,
          z: 3,
          animationEasing: "elasticOut"
        },
        {
          // 分隔线
          type: "pictorialBar",
          itemStyle: {
            normal: {
              color: "#fff"
            }
          },
          symbolRepeat: "fixed",
          symbolMargin: 4,
          symbol: "rect",
          symbolClip: true,
          symbolSize: [2, 14],
          symbolPosition: "start",
          symbolOffset: [1, -1],
          data: seriesData,
          z: 4,
          animationEasing: "elasticOut"
        },
        ]
      };
      this.$nextTick(() => {
        this.$refs.chart.initChart(echarts, chart => {
          // chart.setOption(this.options)
          this.options && chart.setOption(this.options, true);
        });
      })
    }
  }
}
</script>
相关推荐
她似晚风般温柔78912 分钟前
Uniapp + Vue3 + Vite +Uview + Pinia 分商家实现购物车功能(最新附源码保姆级)
开发语言·javascript·uni-app
Jiaberrr1 小时前
前端实战:使用JS和Canvas实现运算图形验证码(uniapp、微信小程序同样可用)
前端·javascript·vue.js·微信小程序·uni-app
everyStudy2 小时前
JS中判断字符串中是否包含指定字符
开发语言·前端·javascript
城南云小白2 小时前
web基础+http协议+httpd详细配置
前端·网络协议·http
前端小趴菜、2 小时前
Web Worker 简单使用
前端
web_learning_3212 小时前
信息收集常用指令
前端·搜索引擎
Ylucius2 小时前
动态语言? 静态语言? ------区别何在?java,js,c,c++,python分给是静态or动态语言?
java·c语言·javascript·c++·python·学习
tabzzz2 小时前
Webpack 概念速通:从入门到掌握构建工具的精髓
前端·webpack
200不是二百2 小时前
Vuex详解
前端·javascript·vue.js
滔滔不绝tao2 小时前
自动化测试常用函数
前端·css·html5