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
| <template>
| <div>
| <h3><icon-font type="icon-title_tubiao" />{{ title }}</h3>
| <div>
| <div class="echarts" ref="echart"></div>
| </div>
| </div>
| </template>
|
| <script>
| import { Icon } from 'ant-design-vue'
| import * as echarts from 'echarts'
| const IconFont = Icon.createFromIconfontCN({
| scriptUrl: '//at.alicdn.com/t/c/font_3968332_p3kji0rhne.js'
| })
| export default {
| name: 'Echarts',
| components: { IconFont },
| props: ['title', 'data'],
| data() {
| return {
| opt: {},
| echarts: {}
| }
| },
| mounted() {
| this.initEcharts()
| },
| methods: {
| initEcharts() {
| this.myChart = echarts.init(this.$refs.echart)
|
| this.opt = {
| tooltip: {
| trigger: 'axis',
| backgroundColor: 'rgba(50,50,50,0.7)',
| textStyle: {
| color: '#fff'
| },
| padding: [10, 30],
| formatter: function (params) {
| let dataStr = ``
| params.forEach((item) => {
| dataStr += `
| <div>
| <div style="margin: 0 8px;">
| <span style="display:inline-block;margin-right:5px;width:20px;height:10px;background-color:${item.color};"></span>
| <span>${item.seriesName}</span>
| <span style="float:right;color:#fff;margin-left:20px;">${item.data}</span>
| </div>
| </div>`
| })
| return dataStr
| }
| },
| legend: {
| data: [],
| icon: 'rect',
| right: 150
| },
| xAxis: {
| show: false,
| type: 'category',
| boundaryGap: true,
| axisTick: {
| show: false
| },
| axisLine: {
| lineStyle: {
| color: '#cdebff'
| }
| },
| axisLabel: { color: '#000' }
| },
| yAxis: {
| type: 'value',
| splitLine: {
| lineStyle: {
| type: 'dashed',
| color: '#cdebff'
| }
| },
| axisLabel: { color: '#000' }
| },
| series: [
| // {
| // name: '主轴电流',
| // type: 'line',
| // // color: '#ff3333',
| // smooth: true,
| // symbol: 'none',
| // lineStyle: { color: '#ff3333' }
| // },
| // {
| // name: '扭矩',
| // type: 'line',
| // // color: '#00ff66',
| // smooth: true,
| // symbol: 'none',
| // lineStyle: { color: '#00ff66' }
| // },
| // {
| // name: '负载',
| // type: 'line',
| // // color: '#0066ff',
| // smooth: true,
| // symbol: 'none',
| // lineStyle: { color: '#0066ff' }
| // },
| // {
| // name: '其他',
| // type: 'line',
| // // color: '#ff9933',
| // smooth: true,
| // symbol: 'none',
| // lineStyle: { color: '#ff9933' }
| // }
| ]
| }
| this.myChart.setOption(this.opt)
| }
| },
| watch: {
| data(val) {
| // const month = []
| // const data = { electricity: [], torsion: [], load: [], other: [] }
| // val.forEach((item) => {
| // month.push(item.month)
| // data.electricity.push(item.electricity)
| // data.torsion.push(item.torsion)
| // data.load.push(item.load)
| // data.other.push(item.other)
| // })
| // this.opt.xAxis.data = month
| // this.opt.series[0].data = data.electricity
| // this.opt.series[1].data = data.torsion
| // this.opt.series[2].data = data.load
| // this.opt.series[3].data = data.other
|
| // this.myChart.setOption(this.opt)
|
| const seriesData = []
| const legendName = []
| val.forEach(item => {
| const seriesItemData = {
| name: '',
| type: 'line',
| smooth: true,
| symbol: 'circle',
| data: []
| }
| console.log(item, 'item')
| legendName.push(item.name)
| seriesItemData.name = item.name
| seriesItemData.data = item.data
| seriesData.push(seriesItemData)
| })
| this.opt.legend.data = legendName
| this.opt.series = seriesData
|
| this.myChart.setOption(this.opt)
| }
| }
| }
| </script>
|
| <style lang="less">
| .echarts {
| width: 100%;
| height: 300px;
| }
| </style>
|
|