echarts 进度条类型柱状图

在这里插入图片描述

父组件:
<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]
	      }
	}
}
子组件:
<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>

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2023-12-18 17:58:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-18 17:58:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-18 17:58:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-18 17:58:02       20 阅读

热门阅读

  1. 【unity】如何让Unity应用在退出时关闭某些服务

    2023-12-18 17:58:02       32 阅读
  2. Hive高级语法

    2023-12-18 17:58:02       33 阅读
  3. 华为HCIP认证H12-821题库上

    2023-12-18 17:58:02       30 阅读
  4. mkdir命令

    2023-12-18 17:58:02       31 阅读
  5. 使用C语言设计并实现一个成绩管理系统

    2023-12-18 17:58:02       42 阅读
  6. 长期供应IMX225LQR-C芯片现货

    2023-12-18 17:58:02       28 阅读
  7. Vue 插槽(Slot):打开组件的灵活大门

    2023-12-18 17:58:02       38 阅读
  8. Spring Boot 如何配置 log4j2

    2023-12-18 17:58:02       43 阅读