BarChart.vue
3.8 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
<template>
<div>
<div id="destination-traffic-chart" />
</div>
</template>
<script>
import echarts from 'echarts'
export default {
data() {
return {
}
},
mounted() {
this.destinationTraffic()
},
methods: {
destinationTraffic() {
const myChart = echarts.init(
document.getElementById('destination-traffic-chart')
)
const option = {
color: new echarts.graphic.LinearGradient(
1, 0, 0, 1,
[
{ offset: 0, color: '#FEAEA1' },
{ offset: 0.5, color: '#FEA198' },
{ offset: 0.8, color: '#FD7B78' },
{ offset: 1, color: '#FD7371' }
]
),
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#283b56'
}
}
},
legend: {
bottom: 10,
itemWidth: 2,
itemHeight: 8,
data: ['订单数量(万件)', '同比增长']
},
dataZoom: {
show: false,
start: 0,
end: 100
},
xAxis: [
{
type: 'category',
boundaryGap: true,
// data: (function() {
// var now = new Date()
// var res = []
// var len = 10
// while (len--) {
// res.unshift(now.toLocaleTimeString().replace(/^\D*/, ''))
// now = new Date(now - 2000)
// }
// return res
// })()
data: ['北京', '天津', '上海', '重庆', '河北', '河南', '云南', '辽宁', '黑龙江', '湖南', '安徽', '山东']
},
{
type: 'category',
boundaryGap: true,
data: (function() {
var res = []
var len = 10
while (len--) {
res.push(10 - len - 1)
}
return res
})()
}
],
yAxis: [
{
type: 'value',
scale: true,
max: 30,
min: 0,
boundaryGap: [0.2, 0.2]
},
{
type: 'value',
scale: true,
max: 1200,
min: 0,
boundaryGap: [0.2, 0.2]
}
],
series: [
{
name: '订单数量(万件)',
type: 'bar',
itemStyle: {
// 柱形图圆角,鼠标移上去效果,如果只是一个数字则说明四个参数全部设置为那么多
emphasis: {
barBorderRadius: 30
},
normal: {
// 柱形图圆角,初始化效果
barBorderRadius: [10, 10, 10, 10]
}
},
barWidth: '30%',
xAxisIndex: 1,
yAxisIndex: 1,
data: (function() {
var res = []
var len = 10
while (len--) {
res.push(Math.round(Math.random() * 1000))
}
return res
})()
},
{
name: '同比增长',
type: 'line',
itemStyle: {
color: '#699AFC'
},
data: (function() {
var res = []
var len = 0
while (len < 10) {
res.push((Math.random() * 10 + 5).toFixed(1) - 0)
len++
}
return res
})()
}
]
}
myChart.setOption(option)
window.addEventListener('resize', function() {
myChart.resize()
})
}
}
}
</script>
<style lang="scss" scoped>
#destination-traffic-chart {
height: 300px;
width: 400px;
margin: 0 auto;
}
</style>