multipleEchart.vue
9.97 KB
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
<template>
<div>
<div class="echart" ref="myChart" :style="{ width: width, height: height }"></div>
</div>
</template>
<script>
export default {
props: {
width: {
type: String,
default: ''
},
height: {
type: String,
default: ''
},
isCloseShowNumTag: {
type: Boolean,
default: false
},
totalData: {
type: Array,
// default: () => []
default() {
return []
}
}
},
data() {
return {
dateArray: [],
customerCount: [], //新增客户
customerRatio: [], //新增客户环比
entmicroCount: [], //新增企微客户
entmicroRatio: [] //新增企微客户环比
}
},
mounted() {
this.$nextTick(() => {
if (this.totalData && this.totalData.length > 0) {
this.dateArray = this.totalData.map(item => item.dateTime) //日期
this.customerCount = this.totalData.map(item => item.newCustomerCount)
this.customerRatio = this.totalData.map(item => item.customerRatio * 100)
this.entmicroCount = this.totalData.map(item => item.newEntmicroCount)
this.entmicroRatio = this.totalData.map(item => item.entmicroRatio * 100)
this.initChart()
}
})
},
watch: {
totalData: {
deep: true,
handler(val) {
this.dateArray = this.totalData.map(item => item.dateTime) //日期
this.customerCount = this.totalData.map(item => item.newCustomerCount)
this.customerRatio = this.totalData.map(item => this.Solution(item.customerRatio, 100))
this.entmicroCount = this.totalData.map(item => item.newEntmicroCount)
this.entmicroRatio = this.totalData.map(item => this.Solution(item.entmicroRatio, 100))
this.initChart()
}
}
},
methods: {
Solution(a, b) {
if (a === 0 || b === 0) return 0 //
let m = 0 //精度
let s1 = a.toString()
let s2 = b.toString()
if (s1.indexOf('.') == -1 && s2.indexOf('.') == -1) {
return a * b
} else {
//计算s1小数点后的位数
m = m + (s1.indexOf('.') >= 0 ? s1.split('.')[1].length : 0)
//计算s2小数点后的位数
m = m + (s2.indexOf('.') >= 0 ? s2.split('.')[1].length : 0)
//除小数点后的所有位数相乘/精度
return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m)
}
},
initChart() {
// 基于准备好的dom,初始化echarts实例
let myChart = this.$echarts.init(this.$refs.myChart)
// 绘制图表
myChart.setOption({
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
crossStyle: {
color: '#999'
}
},
formatter: function(datas) {
var res = datas[0].name + ' | 新增' + '<br/>'
let circleColor
for (var i = 0, length = datas.length; i < length; i++) {
// if (datas[i].seriesName == '新增客户' || datas[i].seriesName == '新增企微客户') {
// res += datas[i].seriesName + ':' + datas[i].data + '人' + '<br/>'
// } else {
// res += datas[i].seriesName + ':' + datas[i].data + '%' + '<br/>'
// }
if (datas[i].seriesName == '全部客户') {
circleColor = '#928DFF'
res += `<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:${circleColor};"></span>` + datas[i].seriesName + ':' + datas[i].data + '人' + '<br/>'
}
if (datas[i].seriesName == '全部客户环比') {
circleColor = '#5850FF'
res += `<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:${circleColor};"></span>` + datas[i].seriesName + ':' + datas[i].data + '%' + '<br/>'
}
if (datas[i].seriesName == '企微客户') {
circleColor = '#FEBE6B'
res += `<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:${circleColor};"></span>` + datas[i].seriesName + ':' + datas[i].data + '人' + '<br/>'
}
if (datas[i].seriesName == '企微客户环比') {
circleColor = '#FE9C1C'
res += `<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:${circleColor};"></span>` + datas[i].seriesName + ':' + datas[i].data + '%' + '<br/>'
}
}
return res
}
// formatter: '{b0}<br/>' + '{a0}: {c0}人<br />{a1}: {c1}%<br />{a2}: {c2}人<br />{a3}: {c3}%'
},
// toolbox: {
// feature: {
// dataView: { show: true, readOnly: false },
// magicType: { show: true, type: ["line", "bar"] },
// restore: { show: true },
// saveAsImage: { show: true },
// },
// },
legend: {
x: 'center',
// y: 'bottom',
bottom: '50px',
// textStyle: {
// //图例的公用文本样式。
// fontSize: 14,
// color: "#333",
// },
// tooltip: {
// show: true
// },
itemGap: 20, //图例每项之间的间隔。横向布局时为水平间隔,纵向布局时为纵向间隔。
// data: ['全部客户', '全部客户环比', '企微客户', '企微客户环比'], //图例的数据数组。
// data: ['新增客户', '新增客户环比', '新增企微客户', '新增企微客户环比'], //图例的数据数组。
data: ['全部客户', '全部客户环比', '企微客户', '企微客户环比'], //图例的数据数组。
inactiveColor: '#ccc' //图例关闭时的颜色。
},
grid: {
//直角坐标系内绘图网格
bottom: '20%', //grid 组件离容器下侧的距离。
left: '1%',
right: '5%',
containLabel: true //grid 区域是否包含坐标轴的刻度标签。
},
dataZoom: [
//dataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息,或者概览数据整体,或者去除离群点的影响。#bed0f7
{
bottom: '30px',
// type: 'inside',
type: 'slider',
show: true,
brushStyle: {
show: false
},
// backgroundColor: '#ff0000',
// borderColor: '#ff0000',
height: '1%',
// borderColor: '#8FDFFE',
// backgroundColor: '#8fdffe99',
handleIcon: 'M512 512m-208 0a6.5 6.5 0 1 0 416 0 6.5 6.5 0 1 0-416 0Z M512 192C335.264 192 192 335.264 192 512c0 176.736 143.264 320 320 320s320-143.264 320-320C832 335.264 688.736 192 512 192zM512 800c-159.072 0-288-128.928-288-288 0-159.072 128.928-288 288-288s288 128.928 288 288C800 671.072 671.072 800 512 800z',
handleColor: '#bed0f7',
handleSize: 15,
handleStyle: {
borderColor: '#bed0f7',
shadowBlur: 4,
shadowOffsetX: 1,
shadowOffsetY: 1,
shadowColor: '#e5e5e5'
},
start: 0,
end: 100
},
{
type: 'inside',
start: 0,
end: 100
}
],
xAxis: [
{
type: 'category',
data: this.dateArray, //['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
axisPointer: {
type: 'shadow'
}
}
],
yAxis: [
{
type: 'value',
name: '单位:人',
min: 0,
max: 100,
interval: 10,
axisLabel: {
formatter: '{value}'
},
splitLine: {
show: false //是否显示分割线
}
},
{
type: 'value',
name: '环比(%)',
// min: "-20",
// max: "20",
// interval: 10,
axisLabel: {
formatter: '{value}'
},
splitLine: {
show: false //是否显示分割线
}
}
],
series: [
{
name: '全部客户',
type: 'bar',
data: this.customerCount, //[33600, 18000, 17500, 20000, 17000, 480, 1000, 800, 520, 650, 920, 600],
label: {
show: this.isCloseShowNumTag ? false : true,
// formatter: '{b}: {c}',
color: '#666666',
position: 'top'
},
itemStyle: {
color: '#928DFF'
}
},
{
name: '全部客户环比',
type: 'line',
yAxisIndex: 1,
data: this.customerRatio, //[2.0, 2.2, -3.3, 4.5, 6.3, -10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2],
itemStyle: {
color: '#5850ff'
}
},
{
name: '企微客户',
type: 'bar',
data: this.entmicroCount, //[22000, 10000, 10000, 13000, 11500, 4000, 7000, 6500, 4500, 5500, 7000, 6000],
itemStyle: {
color: '#FEBE6B'
},
label: {
show: this.isCloseShowNumTag ? false : true,
color: '#666666',
position: 'top'
}
},
{
name: '企微客户环比',
type: 'line',
yAxisIndex: 1,
data: this.entmicroRatio, //[2.6, 2.2, 3.0, 3.8, 6.8, 10.9, 18.3, 23.0, 23.9, 16.0, 10.0, 8.2],
itemStyle: {
color: '#FE9C1C'
}
}
]
})
}
}
}
</script>
<style lang="scss" scoped></style>