Blame view

antis-ncc-admin/src/components/VisualPortal/HBarChart/index.vue 1.48 KB
03207d5d   wwk   1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  <template>
    <el-card shadow="never" class="portal-eChart-box">
      <div slot="header" class="portal-common-title">
        <span>{{title}}</span>
      </div>
      <div class="eChart-box-body">
        <div ref="chart" id="chart" v-show="!isEmpty"></div>
        <div class="portal-common-noData portal-common-noData-eChart" v-show="isEmpty">
          <img src="@/assets/images/portal-nodata.png" alt="" class="noData-img">
          <p class="noData-txt">暂无数据</p>
        </div>
      </div>
    </el-card>
  </template>
  <script>
  import { getProjectMonthLine } from "@/api/home";
  import echarts from 'echarts'
  import resize from '@/components/Charts/mixins/resize'
  export default {
    mixins: [resize],
    props: {
      title: { type: String, default: '' },
      option: { type: Object, default: () => { } }
    },
    data() {
      return {
        chart: null,
        currOption: {},
        isEmpty: false
      }
    },
    created() {
      this.getData();
    },
    methods: {
      getData() {
        getProjectMonthLine().then((res) => {
          window.console.log("柱状图:" + res.data.chartdata);
          this.currOption = res.data.chartdata;
          this.initChart();
        });
      },
      initChart() {
        this.chart = echarts.init(this.$refs.chart);
        this.chart.setOption(this.currOption);
        setTimeout(() => {
          this.$nextTick(() => {
            this.chart.resize();
          });
        }, 50);
      },
    },
    beforeDestroy() {
      if (!this.chart) return;
      this.chart.dispose();
      this.chart = null;
    },
  }
  </script>