fuliqi
2024-09-24 4e2670a63c0ccb399f8c51837a851a8cca3688da
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<template>
  <div class="lineChart-container" ref="lineChart"></div>
</template>
 
<script>
 
export default {
  name: 'lineChart',
  props: {
    workOrderRegion: {
      type: Array,
      default: null,
    },
  },
  data() {
    return {
      name: [],
      data1: [],
      data2: [],
 
      myDrawLine: null
    }
  },
 
  methods: {
    initDrawLine() {
      const that = this
      let option = {
        grid: {
          left: '15%',
          right: '5%'
        },
        tooltip: {
          trigger: 'item',
          formatter: function (params) {
            let str = '<div><p>' + params.name + '</p></div>'
            str += params.marker + params.seriesName + ':' + params.data
            return str
          },
          textStyle: {
            fontSize: 16
          }
        },
 
        // 图例组件
        legend: {
          type: 'plain',
          top: 20,
          data: ['已处理工单数', '未处理工单数'],
          textStyle: {
            color: '#A0AEC0',
            fontSize: 14
          }
        },
 
        // X轴配置
        xAxis: {
          type: 'category',
          boundaryGap: false,
          axisTick: {
            show: true
          },
          axisLine: {
            lineStyle: {
              color: '#A0AEC0',
              type: 'solid'
            }
          },
          axisLabel: {
            color: '#A0AEC0',
            fontSize: 14,
            margin: 20,
            rotate: 30
          },
          data: that.name,
        },
        // Y轴配置
        yAxis: {
          type: 'value',
          splitLine: {
            lineStyle: {
              color: '#A0AEC0',
              type: 'dashed'
            }
          },
          splitNumber: 5,
          axisLine: {
            show: false
          },
          axisLabel: {
            color: '#A0AEC0',
            fontSize: 14,
            margin: 5
          }
        },
        // 系列列表(多个折线图)
        series: [
          {
            name: '已处理工单数',
            type: 'line',
            data: that.data1,
            smooth: true,
            areaStyle: {
              color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {offset: 0, color: '#00a2ff'},
                {offset: 0.5, color: 'rgba(0,162,255,0.1)'},
                {offset: 1, color: 'rgba(0,162,255,0.1)'}
              ])
            },
 
            lineStyle: {
              color: '#00a2ff',
              width: 1
            },
            itemStyle: {
              color: '#00a2ff'
            }
          },
          {
            name: '未处理工单数',
            type: 'line',
            data: that.data2,
            smooth: true,
            areaStyle: {
              color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {offset: 0, color: '#e4b54f'},
                {offset: 0.5, color: 'rgba(228,181,79,0.1)'},
                {offset: 1, color: 'rgba(228,181,79,0.1)'}
              ])
            },
 
            lineStyle: {
              color: '#e4b54f',
              width: 1
            },
            itemStyle: {
              color: '#e4b54f'
            }
          }
        ]
      }
 
      that.myDrawLine = this.$echarts.init(this.$refs.lineChart)
      that.myDrawLine.setOption(option)
      window.addEventListener('resize', function () {
        that.myDrawLine.resize()
      })
    }
  },
 
  watch: {
    workOrderRegion: {
      handler(newV, oldV) {
        this.name = []
        this.data1 = []
        this.data2 = []
        newV.map((item) => {
          this.name.push(item.area);
          this.data1.push(item.doneNum);
          this.data2.push(item.todoNum);
        })
        this.initDrawLine()
      },
      deep: true
    }
  },
  mounted() {
    this.$nextTick(() => {
      setTimeout(() => {
        this.initDrawLine()
      }, 100)
    })
  }
}
</script>
 
<style lang="scss" scoped>
.lineChart-container {
  width: 100%;
  height: 100%;
}
</style>