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>
相关推荐
GISer_Jing12 分钟前
前端图形渲染 html+css、canvas、svg和webgl绘制详解,各个应用场景及其区别
前端·html·图形渲染
零凌林14 分钟前
使用exceljs将excel文件转化为html预览最佳实践(完整源码)
前端·html·excel·vue3·最佳实践·文件预览·exceljs
星空寻流年20 分钟前
css3基于伸缩盒模型生成一个小案例
javascript·css·css3
二十雨辰21 分钟前
[CSS3]属性增强1
前端·css·css3
waterHBO2 小时前
直接从图片生成 html
前端·javascript·html
EndingCoder2 小时前
JavaScript 时间转换:从 HH:mm:ss 到十进制小时及反向转换
javascript
互联网搬砖老肖2 小时前
React组件(一):生命周期
前端·javascript·react.js
我科绝伦(Huanhuan Zhou)2 小时前
深入解析Shell脚本编程:从基础到实战的全面指南
前端·chrome
小马哥编程2 小时前
React和Vue在前端开发中, 通常选择哪一个
前端·vue.js·react.js
aklry2 小时前
uniapp实现在线pdf预览以及下载
前端·pdf·uni-app