index.vue
2.46 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
<template>
<div>
<div id="channel-main" class="chart-line" ref="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: 'line',
data() {
return {
lineStatus: true
}
},
props: {
colorList: {
type: Array
}
},
methods: {
init(chartList, codeName) {
if (chartList.length == 0) {
this.lineStatus = false
return
}
let time = chartList[0].trendItemList.map(item => {
return item.dayTime
})
let seriesList = chartList.map((item, index) => {
let newlyQyCount = []
item.trendItemList.forEach(i => {
newlyQyCount.push(i.newlyQyCount)
})
return {
name: codeName[index],
type: 'line',
data: newlyQyCount,
itemStyle: {
normal: {
color: this.colorList[index],
lineStyle: {
color: this.colorList[index]
}
}
}
}
})
echarts.init(document.getElementById('channel-main')).clear()
let chartDom = document.getElementById('channel-main')
let myChart = echarts.init(chartDom)
let option = {
legend: {
left: 'auto',
icon: 'stack',
itemHeight: 2,
itemWidth: 12,
color: this.colorList
},
tooltip: {
trigger: 'axis'
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
boundaryGap: false,
data: time
},
yAxis: {
type: 'value',
minInterval: 1
},
series: seriesList
}
myChart.setOption(option)
let dataList = []
seriesList.forEach(item => {
dataList = dataList.concat(item.data)
})
if (dataList.every(item => item == 0)) {
this.lineStatus = false
} else {
this.lineStatus = true
}
}
}
}
</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>