zhaowei
2 天以前 54d11f9a2f395e021486e6a31912616274b3feda
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
<template>
  <div id="utilizationRate"></div>
</template>
 
<script>
 
  export default {
    name: 'UtilizationRateChart',
    components: {},
    props: {
      dataSource: {
        type: Array
      }
    },
    watch: {
      dataSource: {
        handler(value) {
          if (value) this.initChart()
        }
      }
    },
    data() {
      return {
        chartContainer: null
      }
    },
    mounted() {
      window.addEventListener('resize', this.handleWindowSizeChange)
    },
    methods: {
      initChart() {
        this.chartContainer = this.$echarts.init(document.getElementById('utilizationRate'))
        const option = {
          tooltip: {
            trigger: 'axis',
            // show:false   //鼠标放置上去是否显示值
            fontSize: this.fontSize(0.16)
          },
          legend: {
            top: '2%',
            right: '2%',
            data: [
              {
                name: '全厂',
                textStyle: {
                  color: '#eee',
                  fontSize: this.fontSize(0.16),
                  fontWeight: 'bold'
                }
              }
            ]
          },
 
          grid: {
            left: '3%',
            right: '3%',
            bottom: '3%',
            top: '15%',
            containLabel: true
          },
          xAxis: {
            type: 'category',
            axisTick: {
              show: true
            },
            boundaryGap: ['20%', '0%'],
            data: ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
            axisLabel: {
              color: '#eee',
              fontSize: '80%',
              fontWeight: 'bold',
              interval: 0
 
            },
            axisLine: {
              lineStyle: {
                color: '#eee'
              }
            }
          },
          yAxis:
            [
              {
                type: 'value',
                axisTick: {
                  show: true
                },
                splitLine: {  //决定是否显示坐标中网格
                  show: true
                },
                min: 0.0,
                position: 'left',
                axisLabel: {
                  show: true,
                  interval: 'auto',
                  formatter: '{value}%',
                  textStyle: {
                    color: '#eee',
                    fontSize: '80%',
                    fontWeight: 'bold'
                  }
                },
                axisLine: {
                  lineStyle: {
                    color: ['white'],
                    width: 1,
                    show: true
                  }
                }
              }
            ],
          series: [
            {
              name: '全厂',
              type: 'line',
              smooth: false,
              symbol: 'circle',
              symbolSize: this.fontSize(0.12),
              data: this.dataSource,
              itemStyle: {
                normal: {
                  width: '10%',
                  color: '#ff9e3c',
                  fontSize: '60%',
                  fontWeight: 'bold'
                }
              }
            }
          ]
        }
        this.chartContainer.setOption(option, true)
      },
 
      //自适应字体方法封装
      fontSize(res) {
        var docEl = document.documentElement,
          clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
        if (!clientWidth) return
        var fontSize = 100 * (clientWidth / 1920)
        return res * fontSize
      },
 
      handleWindowSizeChange() {
        if (this.chartContainer) this.chartContainer.resize()
      }
    }
  }
</script>
 
<style scoped>
 
</style>