vue 用echarts写的进度条组件

£可爱£侵袭症+ 提交于 2019-11-29 21:38:35

组件

<template>
<div class="chart" :style="{height:height,width:width}">
</div>
</template>
<script>
import echarts from "echarts";
export default {
  props: {
    barObj: {
      type: Object
    },
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "150px"
    }
  },
  data() {
    return {
      myChart: null
    };
  },
  mounted() {
    let _this = this;
    _this.init();
    window.addEventListener("resize", function() {
      _this.myChart.resize();
    });
  },
  beforeDestroy() {
    if (!this.myChart) {
      return;
    }
    this.myChart.dispose();
    this.myChart = null;
  },
  methods: {
    init() {
      this.drawLine();
    },
    drawLine() {
      let self = this;
      self.myChart = echarts.init(this.$el);
      self.myChart.clear();
      let data = self.barObj;
      // 绘制图表
      self.myChart.setOption({
        grid: {
          top: '0',
          left: '0',
          bottom: '0',
          right: '0'
        },
        yAxis: [{
          type: 'category',
          inverse: true,
          axisTick: {
            show: false
          },
          axisLabel: {
            show: false
          },
          axisLine: {
            show: false
          }
        }],
        xAxis: [{
          type: 'value',
          axisLabel: {
            show: false
          },
          axisLine: {
            show: false
          },
          splitLine: {
            show: false
          }
        }],
        series: [{
          type: 'bar',
          barWidth: data.barWidth,
          data: data.barData,
          label: {
            normal: {
              show: false,
            }
          },
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
                offset: 0,
                color: data.color[0] // 0% 处的颜色
              }, {
                offset: 1,
                color: data.color[1] // 100% 处的颜色
              }], false),
              barBorderRadius: data.barWidth / 2
            }
          }
        }, {
          type: "bar",
          barWidth: data.barWidth,
          xAxisIndex: 0,
          barGap: "-100%",
          data: [100],
          itemStyle: {
            normal: {
              color: "#F5F7F7",
              barBorderRadius: data.barWidth / 2
            }
          },
          zlevel: -1
        }]
      });
    }
  }
};
</script>
<style lang="scss" scoped>

</style>

使用

<template>
<div class="land_co land-wrap">
  <div class="land_lyxz">
    <jump name="不动产登记情况" :index="index"></jump>
    <div class="content">
      <div v-for="(item,index) in barList" :key="index" class="bar-div">
        <div class="bar-title-div">
          <span class="bar-title">{{item.title}}</span>
          <span class="bar-val">{{item.value}}</span>
          <span class="bar-ratio">{{item.ratio}}</span>
        </div>
        <bar-progress :bar-obj="item.barObj" height="20px"></bar-progress>
      </div>
    </div>
  </div>
</div>
</template>

<script>
import jump from "@/components/jump";
import barProgress from "../components/chart/barProgress";
export default {
  props: {
    index: {
      default: 1
    }
  },
  data() {
    return {
      barList: [{
          title: "共颁发不动产权证 (本)",
          value: "423,163",
          ratio: "↑ 27.98%",
          barObj: {
            barData: ["27.98"],
            color: ["#46D675", "#BEF9A9"],
            barWidth: 10
          }
        },
        {
          title: "不动产证明(份)",
          value: "133,668",
          ratio: "↑ 9.42%",
          barObj: {
            barData: ["9.42"],
            color: ["#FFBA00", "#FFFA78"],
            barWidth: 10
          }
        }
      ]
    };
  },
  methods: {},
  watch: {
    jsyd: {
      handler() {
        this.$nextTick(() => {});
      },
      deep: true
    }
  },
  mounted() {},
  directives: {},
  components: {
    jump,
    barProgress
  }
};
</script>

<style lang="scss" scoped>
@import "../../../styles/mixin";
@import "../../../styles/zrzy_land_lyxz";
.land-wrap {
  .content {
    padding-right: 20px;
    margin-right: 20px;
    box-sizing: border-box;
    font-size: 24px;
    color: #191f25;
  }
  .bar-div {
    margin-bottom: 44px;
  }
  .bar-title-div {
    margin-bottom: 16px;
    margin-top: 50px;
    position: relative;
    .bar-title {
      margin-right: 20px;
    }
    .bar-value {
      font-size: 38px;
      font-weight: bold;
    }
    .bar-ratio {
      position: absolute;
      color: #FF3939;
      font-weight: bold;
      right: 0;
    }
  }
}
</style>

在这里插入图片描述

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!