LineChart.vue
1.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
<template>
<div class="line-box">
<p v-if="title" class="title">{{ title }}</p>
<div id="line-chart" class="line-chart"></div>
<div class="rank-box">
<div>
<p :class="[ 'rank-title', rankFlag == 'first' ? 'rank-active' : '' ]" @click="handleRankChange('first')">前5{{ storeOrBrandTxt }}</p>
<p :class="[ 'rank-title', rankFlag == 'last' ? 'rank-active' : '' ]" @click="handleRankChange('last')">后5{{ storeOrBrandTxt }}</p>
</div>
</div>
</div>
</template>
<script>
import * as echarts from 'echarts'
import options from './lineOptions'
export default {
name: 'LineChart',
props: {
// height: {
// type: String,
// default: '19.8vh'
// },
apiName: {
type: String,
default: ''
},
title: {
type: String,
default: ''
},
storeOrBrandTxt: {
type: String,
default: '门店'
}
},
data() {
return {
// first,last
rankFlag: 'first',
lineOptions: JSON.parse(JSON.stringify(options))
// chartHeight: this.height
}
},
created() {
},
mounted() {
this.drawLine()
},
methods: {
drawLine() {
var lineDom = document.getElementById('line-chart')
var lineChart = echarts.init(lineDom)
lineChart.setOption(this.lineOptions)
},
handleRankChange(value) {
this.rankFlag = value
}
}
}
</script>
<style lang="scss" scoped>
p {
margin: 0 0;
}
.line-box {
color: #ffffff;
padding: 4px 8px;
font-size: 0.75em;
.title {
height: 17px;
color: #e8e8e8;
}
.line-chart {
height: calc(100% - 25px - 30px);
}
.rank-box {
display: flex;
height: 30px;
.rank-title {
box-sizing: border-box;
font-size: 0.6em;
background: #353535;
padding: 1px 5px;
height: 15px;
line-height: 15px;
opacity: 0.7;
cursor: pointer;
}
.rank-active {
opacity: 1;
color: #ffffff;
background: #eb6001;
}
}
}
</style>