Xxxu
2020-07-07 4f953ffc89fc95f83b152e914c5e65938b440f17
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
183
184
185
186
<template>
    <div id='windChartBody'>
        <img height='20px' width='70%' style='margin-top:15px' src='~@/assets/img/weather/wind-chart-title.png'>
        <el-row>
            <el-col :span='24' style='text-align:right'>
                <div>
                    <el-button @click="drawChart(2)" id='month' style='margin:0px;margin-right:10px' class='cycleBtn'></el-button>
                    <el-button @click="drawChart(1)" id='week' style='margin:0px' class='cycleBtn'></el-button>
                    <el-button @click="drawChart(0)" id='day' style='margin:0px' class='cycleBtn'></el-button>
                </div>
            </el-col>
        </el-row>
        <div id='windChart' style='margin-top:20px'></div>
    </div>
</template>
<script>
import echarts from 'echarts'
export default {
  data () {
    return {
      chartHeight: 100,
      windListOfCount: [],
      windListOfDay: [],
      windListOfMonth: [],
      timeListOfCount: [],
      timeListOfDay: [],
      timeListOfMonth: []
    }
  },
  computed: {
    getStreetlightId () {
      return this.$store.state.weather.streetlightIdOfWeather
    },
    getChartHeight () {
      return this.$store.state.weather.chartHeight
    },
    getDataListOfCount () {
      return this.$store.state.weather.dataListOfCount
    },
    getDataListOfDay () {
      return this.$store.state.weather.dataListOfDay
    },
    getDataListOfMonth () {
      return this.$store.state.weather.dataListOfMonth
    }
  },
  watch: {
    getChartHeight (curVal, oldVal) {
      this.chartHeight = curVal
      this.init()
    },
    getStreetlightId (curVal, oldVal) {
      this.windListOfCount = []
      this.windListOfDay = []
      this.windListOfMonth = []
      this.timeListOfCount = []
      this.timeListOfDay = []
      this.timeListOfMonth = []
      let _this = this
      setTimeout(function () {
        _this.drawChart(0)
      }, 1000)
    },
    getDataListOfCount (curVal, oldVal) {
      this.windListOfCount = []
      this.timeListOfCount = []
      var list = curVal
      let _this = this
      list.forEach(function (item, index) {
        _this.windListOfCount.unshift(item.windSpeed)
        _this.timeListOfCount.unshift(item.createTime)
      })
    },
    getDataListOfDay (curVal, oldVal) {
      this.windListOfDay = []
      this.timeListOfDay = []
      var list = curVal
      let _this = this
      list.forEach(function (item, index) {
        _this.windListOfDay.unshift(item.windSpeed)
        _this.timeListOfDay.unshift(item.createTime)
      })
    },
    getDataListOfMonth (curVal, oldVal) {
      this.windListOfMonth = []
      this.timeListOfMonth = []
      var list = curVal
      let _this = this
      list.forEach(function (item, index) {
        _this.windListOfMonth.unshift(item.windSpeed)
        _this.timeListOfMonth.unshift(item.createTime)
      })
    }
  },
  activated () {},
  methods: {
    init () {
      var windChartBody = document.getElementById('windChartBody')
      var windChart = document.getElementById('windChart')
      windChartBody.style.height = this.chartHeight - 20 + 'px'
      windChart.style.height = this.chartHeight - 70 + 'px'
    },
    drawChart (val) {
      var windList
      var TimeList
      if (val === 0) {
        windList = this.windListOfCount
        TimeList = this.timeListOfCount
      } else if (val === 1) {
        windList = this.windListOfDay
        TimeList = this.timeListOfDay
      } else if (val === 2) {
        windList = this.windListOfMonth
        TimeList = this.timeListOfMonth
      }
      var option = {
        animationDuration: 2000,
        color: ['#1176C3'],
        tooltip: {
          trigger: 'axis'
        },
        xAxis: [
          {
            type: 'category',
            scale: true,
            min: 0,
            data: TimeList,
            axisLine: {
              lineStyle: {
                color: '#3F68A0'
              }
            },
            axisLabel: {
              textStyle: {
                color: 'white'
              }
            }
          }
        ],
        yAxis: [
          {
            min: 0,
            type: 'value',
            scale: true,
            name: 'm/s',
            boundaryGap: [0.2, 0.2],
            axisLine: {
              lineStyle: {
                color: '#3F68A0'
              }
            },
            axisLabel: {
              textStyle: {
                color: 'white'
              }
            },
            splitLine: {
              // 坐标轴在 grid 区域中的分隔线
              show: false
            }
          }
        ],
        series: [
          {
            symbolSize: 0,
            name: '风速',
            type: 'bar',
            data: windList,
            itemStyle: {
              normal: {
                lineStyle: {
                  color: 'red',
                  width: 2
                }
              }
            }
          }
        ]
      }
 
      var tempChart = echarts.init(document.getElementById('windChart'))
      tempChart.setOption(option)
    }
  }
}
</script>