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
<template>
  <div class="chart-container" :id="chartContainerId"></div>
</template>
 
<script>
  import signageApi from '@/api/signage'
 
  export default {
    name: 'MonthUtilizationRateTrend',
    components: {},
    props: {
      currentProductionId: {
        type: String
      },
      toDecimal2NoZero: {
        type: Function
      }
    },
    data() {
      return {
        chartContainer: null,
        chartContainerId: 'left-col-chart2'
      }
    },
    mounted() {
      window.addEventListener('resize', this.handleWindowResize)
      if (!this.currentProductionId) return
      this.getChartDataByApi()
    },
    beforeDestroy() {
      window.removeEventListener('resize', this.handleWindowResize)
    },
    methods: {
      getChartDataByApi() {
        const that = this
        this.chartContainer = this.$echarts.init(document.getElementById(this.chartContainerId))
        signageApi.getMonthUtilizationRateApi(this.currentProductionId)
          .then(res => {
            if (!res.success) return
            that.initChart(res.result)
          })
      },
 
      initChart(dataObj) {
        const seriesArr = []
        const option = {
          color: ['#538dd6', '#ffff01', '#0bae8d', '#e26c0a', '#F6E1BE', '#7030a0', '#0ad0bb', '#FF9297', '#A40035'],
          tooltip: {
            trigger: 'axis',
          },
          legend: {
            //type:'scroll',
            show: false,
            width: '100%',
            height: 8,
            itemWidth: 12,
            itemGap: 5,
            itemHeight: 10,
            textStyle: {
              fontSize: '0%',
              color: '#fff'
            }
          },
          grid: {
            left: '1%',
            right: '5%',
            bottom: '1%',
            top: '5%',
            containLabel: true
          },
          'dataZoom': [
            {
              'type': 'inside',
              'show': true,
              'xAxisIndex': [
                0
              ],
              'start': 0,
              'end': 100
            }
          ],
          xAxis: {
            type: 'category',
            name: '',
            // min:-35,
            // boundaryGap: false,
            data: [],
            axisLabel: {
              color: '#fff',
              rotate: 45,
              fontSize: '55%'
            },
            axisLine: {
              lineStyle: {
                color: '#fff'
              }
            }
          },
          yAxis: {
            type: 'value',
            name: '',
            axisLabel: {
              formatter: '{value} %',
              color: '#fff',
              fontSize: '70%'
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: '#fff'
              }
            },
            splitLine: {
              show: false
            }
          },
          series: []
        }
        dataObj.dataList.forEach(item1 => {
          const dataArr = []
          item1.utilizationRateList.forEach(item2 => {
            dataArr.push({
              value: item2.utilizationRate,
              hostType: (item2.date ? item2.date : '')
            })
          })
          if (item1.productionName == '总厂') {
            seriesArr.push({
              name: item1.productionName,
              type: 'line',
              lineStyle: { width: 4, color: '#9cff45' },
              itemStyle: { color: '#50ff45' },
              symbol: 'circle',
              data: dataArr
            })
          } else {
            seriesArr.push({
              name: item1.productionName,
              type: 'line',
              lineStyle: { width: 2 },
              symbol: 'circle',
              data: dataArr
            })
          }
        })
        option.xAxis.data = dataObj.dateList
        option.series = seriesArr
        this.chartContainer.setOption(option, true)
      },
 
      /**
       * 窗口尺寸变化时触发
       * 调整图表尺寸以适应分辨率
       */
      handleWindowResize() {
        if (this.chartContainer) this.chartContainer.resize()
      }
    }
  }
</script>