DESKTOP-GJP2N7J\lx
2023-08-11 49cd08187c9c49df199a954bd0a5a5bca40f8f1a
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<template>
  <div id="chart-container" :style="{width:width,height:height}">
  </div>
</template>
 
<script>
import { rtuTotalAlarmAnalysis } from '@/cpx_sewage/api/operationManage/rtuMonitor'
import * as echarts from 'echarts'
export default {
  name: 'SingleLineChart',
  props: {
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    chartData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      chart: null
    }
  },
  watch: {
    chartData: {
      immediate: true,
      deep: true,
      handler(newVal, oldVal) {
        if (this.chart) {
          if (newVal) {
            this.setOptions(newVal)
          } else {
            this.setOptions(oldVal)
          }
        }
      }
    }
  },
  mounted() {
    this.initChart()
    if (this.chart) {
      window.addEventListener('resize', this.$_handleResizeChart)
    }
  },
  beforeDestroy() {
    if (!this.chart) {
      return false
    }
    this.chart.dispose()
    this.chart = null
    window.removeEventListener('resize', this.$_handleResizeChart)
  },
  methods: {
    $_handleResizeChart() {
      this.chart.resize()
    },
    async setOptions({ time, Data, config } = {}) {
      // prettier-ignore
      const res = await rtuTotalAlarmAnalysis({ })
      const data = res.data
      const dateList = data.map(function(item) {
        return item.report_time
      })
      const valueList = data.map(function(item) {
        return item.alarmCount
      })
      const option = {
        // Make gradient line here
        tooltip: {
          show: true,
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        xAxis: {
          type: 'category',
          data: dateList,
          // 设置x轴的数据和刻度线对齐
          boundaryGap: false
        },
        yAxis: {
          // 取消Y轴的轴线
          axisLine: {
            show: false
          },
          type: 'value'
        },
        series: [{
          name: '累计报警数量 (次)',
          type: 'line',
          showSymbol: false, // 取消折线上面的点
          // eslint-disable-next-line standard/array-bracket-even-spacing
          data: valueList,
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1,
                [{ offset: 1, color: '#fabb5c' }, { offset: 0.3, color: '#f99331' }, { offset: 0.5, color: '#da6518' }, { offset: 0.2, color: 'red' }])
            }
          }
 
        }] }
 
      this.chart.setOption(option)
    },
    // 表格初始化
    initChart() {
      this.chart = echarts.init(this.$el)
      // 渲染表格
      this.setOptions(this.chartData)
    }
  }
}
</script>
 
<style>
* {
  margin: 0;
  padding: 0;
}
#chart-container {
  position: relative;
  height: 100vh;
  overflow: hidden;
}
</style>