loulijun2021
2023-03-03 0aa79c7b9926e01f61de7c6514ea1deffe3bee7c
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<template>
  <div>
    <div class="body" :style="{height:mainHeight+'px'}">
      <div style="margin: 10px auto;width: 1680px;background-color: #fff" :style="{height:mainHeight+'px'}">
 
        <div style="margin: 20px auto;width: 1600px" :style="{height:(mainHeight-60)+'px'}">
          <div id="Echarts" style="width: 100%;height: 100%" />
        </div>
      </div>
    </div>
  </div>
</template>
 
<script>
import * as echarts from 'echarts'
import { QuaneryDefectReportSearch } from '@/api/bbgl'
 
export default {
  name: 'Pzyc',
  data() {
    return {
      mainHeight: 400,
      echartsData: []
    }
  },
  created() {
    window.addEventListener('resize', this.getHeight)
    this.getHeight()
  },
  mounted() {
    this.getQuaneryDefectReportSearch()
  },
  methods: {
    // 获取页面高度
    getHeight() {
      this.$nextTick(() => {
        this.mainHeight = window.innerHeight - 85
      })
    },
    async getQuaneryDefectReportSearch() {
      const res = await QuaneryDefectReportSearch()
      if (res.code === '200') {
        this.echartsData = res.data
        this.getEcharts()
      }
    },
    getEcharts() {
      const option = {
        title: {
          text: '品质异常排行报表',
          left: '50%',
          top: '5%',
          textAlign: 'center',
          textStyle: {
            // color: '#fff',
            color: '#000',
            fontSize: '20',
            fontWeight: 'bolder'
          }
        },
        // backgroundColor: '#323a5e',
        backgroundColor: 'transparent',
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器,坐标轴触发有效
            type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
          }
        },
        grid: {
          left: '2%',
          right: '4%',
          bottom: '10%',
          top: '15%',
          containLabel: true
        },
        // legend: {
        //   data: ['1', '2', '3'],
        //   right: 10,
        //   top: 12,
        //   textStyle: {
        //     color: '#fff'
        //   },
        //   itemWidth: 12,
        //   itemHeight: 10
        //   // itemGap: 35
        // },
        xAxis: {
          name: '种类',
          nameTextStyle: {
            color: '#000',
            fontSize: 16,
            lineHeight: 20
          },
          type: 'category',
          data: this.echartsData.map(r => r.name),
          splitLine: {
            show: false
          },
          axisTick: {
            show: true
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#000'
            }
          },
          axisLabel: {
            interval: 0,
            rotate: 20,
            textStyle: {
              fontSize: 16,
              color: '#000',
              fontFamily: 'Microsoft YaHei'
            }
          }
        },
        yAxis: {
          name: '数量',
          max: Math.ceil(Math.max(...this.echartsData.map(r => r.cont)) * 1.1), // 取数组里面最大的值乘1.1倍的整数的天花板
          interval: 1,
          nameTextStyle: {
            color: '#000',
            fontSize: 16,
            lineHeight: 20
          },
          type: 'value',
          // max: '1200',
          axisTick: {
            show: true
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#000'
            }
          },
          splitLine: {
            show: false,
            lineStyle: {
              // color: 'rgba(255,255,255,0.3)'
              color: '#000'
            }
          },
          axisLabel: {
            // interval: 0,
            // rotate: 20,
            textStyle: {
              fontSize: 16,
              color: '#000',
              fontFamily: 'Microsoft YaHei'
            }
          }
        },
        dataZoom: [{
          show: true,
          height: 30,
          xAxisIndex: [
            0
          ],
          bottom: 30,
          start: 10,
          end: 80,
          handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
          handleSize: '110%',
          handleStyle: {
            // color: '#d3dee5'
            color: '#000'
          },
          textStyle: {
            color: '#000'
          },
          // borderColor: '#90979c'
          borderColor: '#000',
          fillerColor: `rgba(42, 197, 137, 0.1)`
        }, {
          type: 'inside',
          show: true,
          height: 15,
          start: 1,
          end: 35
        }
        ],
        series: [{
          name: '数量',
          type: 'bar',
          barWidth: '15%',
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#000'
            }
          },
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                offset: 0,
                // color: '#fccb05'
                color: `rgba(42, 197, 137, 1)`// 0% 处的颜色
              }, {
                offset: 1,
                color: `rgba(187, 236, 218, 1)` // 100% 处的颜色
                // color: '#f5804d'
              }]),
              barBorderRadius: 12
            }
          },
          data: this.echartsData.map(r => r.cont)
        }
          // {
          //   name: '2',
          //   type: 'bar',
          //   barWidth: '15%',
          //   itemStyle: {
          //     normal: {
          //         color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          //             offset: 0,
          //             color: '#8bd46e'
          //         }, {
          //             offset: 1,
          //             color: '#09bcb7'
          //         }]),
          //         barBorderRadius: 11,
          //     }
          //   },
          //   data: [400, 500, 500, 500, 500, 400,400, 500, 500]
          // },
          // {
          //   name: '3',
          //   type: 'bar',
          //   barWidth: '15%',
          //   itemStyle: {
          //     normal: {
          //         color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          //             offset: 0,
          //             color: '#248ff7'
          //         }, {
          //             offset: 1,
          //             color: '#6851f1'
          //         }]),
          //     barBorderRadius: 11,
          //     }
          //   },
          //   data: [400, 600, 700, 700, 1000, 400, 400, 600, 700]
          // }
        ]
      }
 
      var app = {
        currentIndex: -1
      }
 
      const myChart = echarts.init(document.getElementById('Echarts'))
 
      // setInterval(function() {
      //   var dataLen = option.series[0].data.length
      //
      //   // 取消之前高亮的图形
      //   myChart.dispatchAction({
      //     type: 'downplay',
      //     seriesIndex: 0,
      //     dataIndex: app.currentIndex
      //   })
      //   app.currentIndex = (app.currentIndex + 1) % dataLen
      //   // console.log(app.currentIndex);
      //   // 高亮当前图形
      //   myChart.dispatchAction({
      //     type: 'highlight',
      //     seriesIndex: 0,
      //     dataIndex: app.currentIndex
      //   })
      //   // 显示 tooltip
      //   myChart.dispatchAction({
      //     type: 'showTip',
      //     seriesIndex: 0,
      //     dataIndex: app.currentIndex
      //   })
      // }, 1000)
 
      if (option.textStyle == null) {
        option.textStyle = {
          fontFamily: 'Microsoft YaHei',
          color: '#ffffff'
        }
      }
 
      // 使用刚指定的配置项和数据显示图表。
      myChart.clear()
      myChart.setOption(option, true)
 
      window.addEventListener('resize', function() {
        myChart.resize()
      })
 
      return myChart
    }
  }
}
</script>
 
<style scoped>
 
</style>