riku
2024-05-06 1534aee0339dee8000cdd26c21797cf3ad391f7a
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<template>
  <BaseCard size="medium">
    <template #content>
      <div ref="lineChart" class="line-chart"></div>
    </template>
    <template #footer>
      <!-- 单页数据量-->
      <SliderBar></SliderBar>
    </template>
  </BaseCard>
</template>
 
<script>
import * as echarts from 'echarts';
import { FactorDatas } from '@/model/FactorDatas';
import { factorName } from '@/constant/factor-name';
import { factorLineOption } from '@/utils/chart/chart-option';
 
export default {
  props: {
    factorDatas: {
      type: FactorDatas
      // default: () => new FactorDatas()
    },
    selectFactorType: {
      type: Array,
      default: () => ['1']
    }
  },
  data() {
    return {
      lineChart: null,
      option: null
    };
  },
  watch: {
    factorDatas: {
      handler() {
        this.refreshChart();
      },
      deep: true
    },
    selectFactorType: {
      handler() {
        this.refreshChart();
      },
      deep: true
    }
  },
  computed: {
    /**
     * 获取横坐标
     */
    xAxis() {
      return this.factorDatas.times.map((v) => {
        return v.split(' ')[1];
      });
    },
    /**
     * 获取监测数据纵坐标
     */
    allSeries() {
      const res = [];
      for (const key in this.factorDatas.factor) {
        if (Object.hasOwnProperty.call(this.factorDatas.factor, key)) {
          const e = this.factorDatas.factor[key];
          res.push({
            key: key,
            name: factorName[e.factorName],
            type: 'line',
            data: e.datas.map((v) => v.factorData),
            showAllSymbol: true,
            animationDelay: function (idx) {
              return idx * 10;
            }
          });
        }
      }
      return res;
    },
    showSeries() {
      return this.allSeries.filter((s) => {
        return this.selectFactorType.includes(s.key);
      });
    },
    legends() {
      return this.showSeries.map((s) => {
        return s.name;
      });
    }
  },
  methods: {
    initChart() {
      this.lineChart = echarts.init(this.$refs.lineChart);
    },
    refreshChart() {
      const option = factorLineOption(
        this.xAxis,
        this.showSeries,
        this.legends
      );
      this.lineChart.setOption(option, { notMerge: true });
    }
  },
  mounted() {
    this.initChart();
  }
};
</script>
<style scoped>
.line-chart {
  /* width: 200px; */
  height: 280px;
}
</style>