linechart.vue
2.56 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
<template>
<div>
<div id="channel-main" class="chart-line" v-show="lineStatus"></div>
<div class="chart-line-empty" v-show="!lineStatus">
<img src="@/assets/img/empty.png" />
<div class="chart-empty-d">暂无数据</div>
</div>
</div>
</template>
<script>
import * as echarts from 'echarts'
export default {
name: 'linechart',
data() {
return {
lineStatus: true
}
},
methods: {
getChart(lineData) {
let entMicroCount = lineData.map(item => {
return item.entMicroCount
})
let notAddEntMicroCount = lineData.map(item => {
return item.notAddEntMicroCount
})
const lengthC = entMicroCount.length - 1
if (notAddEntMicroCount.every(item => item == 0) && entMicroCount.every(item => item == 0)) {
this.lineStatus = false
return
}
this.lineStatus = true
let dateTime = lineData.map(item => {
return item.dayTime
})
let chartDom = document.getElementById('channel-main')
let myChart = echarts.init(chartDom)
let option
option = {
legend: {
left: 'auto',
icon: 'stack',
itemHeight: 2,
textStyle: { color: ['#5850FF', '#FF6D00'] },
itemWidth: 12
},
tooltip: {
trigger: 'axis'
},
color: ['#5850FF', '#FF6D00'],
grid: {
left: '3%',
right: '4%',
bottom: '15%',
containLabel: true
},
dataZoom: [
{
startValue: lengthC - 29,
endValue: lengthC
},
{
type: 'inside',
startValue: lengthC - 29,
endValue: lengthC
}
],
xAxis: {
type: 'category',
boundaryGap: false,
data: dateTime
},
yAxis: {
type: 'value',
minInterval: 1
},
series: [
{
name: '未加企微客户数',
type: 'line',
lineStyle: { color: '#5850FF' },
data: notAddEntMicroCount
},
{
name: '企微客户数',
type: 'line',
lineStyle: { color: '#FF6D00' },
data: entMicroCount
}
]
}
option && myChart.setOption(option)
}
}
}
</script>
<style scoped lang="scss">
.chart-line {
height: 300px;
}
.chart-line-empty {
height: 300px;
text-align: center;
color: #666;
img {
margin-top: 100px;
width: 64px;
height: 32px;
margin-bottom: 12px;
}
}
</style>