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
| <template>
| <div class="chart-container" :id="chartContainerId"></div>
| </template>
|
| <script>
| import * as echarts from 'echarts'
| import signageApi from '@/api/signage'
|
| export default {
| name: 'DayUtilizationRateTrend',
| components: {},
| props: {
| currentProductionId: {
| type: String
| },
| toDecimal2NoZero: {
| type: Function
| }
| },
| data() {
| return {
| chartContainer: null,
| chartContainerId: 'left-col-chart4'
| }
| },
| 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.getDayUtilizationRateApi(this.currentProductionId)
| .then(res => {
| if (!res.success) return
| that.initChart(res.result)
| })
| },
|
| initChart(dataObj) {
| const seriesData = []
| const option = {
| tooltip: {
| show: true,
| trigger: 'axis',
| formatter: function(params) {
| return '<span style="display:inline-block; width:10px; height:10px; border-radius:100px; margin-right:5px; background:' + params[0].color + '"></span> ' + params[0].name + '   ' + '<span style="font-weight: bold"> ' + params[0].value + '%' + '</span>'
| }
| },
| legend: {
| show: false,
| data: [],
| itemWidth: 12,
| itemHeight: 12,
| textStyle: { //图例文字的样式
| //fontSize:14,
| color: '#fff'
| }
| },
| grid: {
| left: '3%',
| right: '4%',
| bottom: '-3%',
| top: '5%',
| containLabel: true
| },
| xAxis: [
| {
| type: 'category',
| data: [],
| axisLine: {
| lineStyle: {
| color: '#fff'
| }
| },
| axisLabel: {
| color: '#fff',
| rotate: 45,
| fontSize: '55%'
| }
| }
| ],
| yAxis: [
| {
| type: 'value',
| data: [],
| axisLine: {
| show: true,
| lineStyle: {
| color: '#fff'
| }
| },
| axisLabel: {
| formatter: '{value} %',
| color: '#fff',
| fontSize: '70%'
| },
| splitLine: {
| lineStyle: {
| color: '#626262'
| }
| }
| }
| ],
| dataZoom: [
| {
| type: 'inside',
| show: true,
| xAxisIndex: [0],
| start: 0,
| end: 100
| }
| ],
| series: [
| {
| name: '利用率',
| type: 'bar',
| barWidth: '50%',//柱图宽度
| data: [],
| label: {
| show: true,
| position: 'inside',
| padding: [1, 2],
| fontSize: '60%',
| color: '#fff',
| formatter: '{c}%',
| backgroundColor: '#4fb327',
| shadowColor: '#153e04',
| shadowBlur: 5,
| shadowOffsetX: 3,
| shadowOffsetY: 5,
| borderRadius: 5
| },
| //barCategoryGap:'180%',
| itemStyle: {
| color: params => {
| const colorList = ['#538dd6', '#ffff01', '#0bae8d', '#e26c0a', '#F6E1BE', '#7030a0', '#0ad0bb', '#FF9297', '#A40035']
| return colorList[params.dataIndex]
| },
| emphasis: {
| barBorderRadius: 13,
| shadowBlur: 18,
| shadowColor: 'rgba(218,170, 58, 0.8)'
| }
| }
| }
| ]
| }
| dataObj.dataList.forEach(item => {
| seriesData.push({
| value: item.utilizationRate,
| hostType: (item.productionName ? item.productionName : '')
| })
| })
| option.xAxis[0].data = dataObj.productionList
| option.series[0].data = seriesData
| this.chartContainer.setOption(option, true)
| },
|
| /**
| * 窗口尺寸变化时触发
| * 调整图表尺寸以适应分辨率
| */
| handleWindowResize() {
| if (this.chartContainer) this.chartContainer.resize()
| }
| }
| }
| </script>
|
|