百分比组件

在这里插入图片描述

//组件
<template>
  <div :class="className" :style="{ height: height, width: width }" style="overflow: hidden;" />
</template>
  
  <script>
export default {
  props: {
    className: {
      type: String,
      default: "chart",
    },
    dataOption: {
      type: Array,
      default: [],
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
    },
  },
  data() {
    return {
      chart: null,
      dataValue: [],
    };
  },
  mounted() {
    let that = this;
    this.$nextTick(() => {
      setTimeout(function () {
        that.initChart();
      }, 500);
    });
  },
  watch: {
    dataOption: {
      deep: true,
      handler(val) {
        this.initChart();
      },
    },
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = this.$echarts.init(this.$el, "macarons");
      this.chart.setOption({
        grid: {
          left: "0px",
          right: "0%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
          splitLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          max: 100,
        },
        yAxis: {
          type: "category",
          splitLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
        },
        series: [
          {
            name: "XXX",
            type: "pictorialBar",
            yAxisIndex: 0,
            symbolSize: [20, 20],
            symbolOffset: [16, 0],
            z: 12,
            itemStyle: {
              normal: {
                color: "#73b605",
              },
            },
            data: [
              {
                value: this.dataOption[0],
                symbolPosition: "end",
              },
            ],
          },
          {
            name: "XXX",
            type: "pictorialBar",
            yAxisIndex: 0,
            symbolSize: [10, 10],
            symbolOffset: [11, 0],
            z: 13,
            itemStyle: {
              normal: {
                color: "#fff",
              },
            },
            data: [
              {
                value: this.dataOption[0],
                symbolPosition: "end",
              },
            ],
          },
          {
            type: "bar",
            itemStyle: {
              normal: {
                color: "#73b605",
                opacity: 0.7,
                barBorderRadius: 5,
              },
            },
            showBackground: true,
            backgroundStyle: {
              color: "rgba(225, 230, 239)",
              borderRadius: [500, 500, 500, 500],
            },
            barWidth: 10,
            barGap: "-100%", // Make series be overlap
            data: this.dataOption,
          },
        ],
      });
    },
  },
};
</script>
  
//使用组件

1、引入

<scheduleChart :width="'87%'" :height="'30px'" :dataOption="dataOption"></scheduleChart>

dataOption: [80],

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值