LineCharts.vue
3.05 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
<template>
<div>
<div :id="domId" style="width: 100%;" :style="{ height }"></div>
</div>
</template>
<script>
import * as echarts from 'echarts'
export default {
name: 'BarLineChart',
props: {
height: {
type: String
},
domId: {
type: String,
default: 'bar-line'
},
dataList: {
type: Array,
default: () => []
},
xAxisData: {
type: Array,
default: () => ['1', '2', '3', '4', '5', '6']
},
linetype: Number,
lineChartsYear: {
type: String,
default: ''
}
},
data() {
return {
barLineOptions: null,
}
},
mounted() {
this.barLineDom = document.getElementById(this.domId)
this[this.domId] = echarts.init(this.barLineDom)
},
methods: {
drawBarLine() {
this.barLineOptions = {
grid: {
right: '5%',
left: `${this.linetype == 1 ? '13%' : '5%'}`
},
xAxis: {
type: 'category',
// name: (this.linetype == 1 ? '周' : '天')+(this.lineChartsYear && '\n('+this.lineChartsYear + '年'+')'),
// nameLocation: 'center',
// nameGap: 20,
// nameTextStyle: {
// fontSize: 10,
// lineHeight: 16
// },
boundaryGap: false,//坐标轴两边留白
data: this.xAxisData,
axisLabel: { //坐标轴刻度标签的相关设置。
interval: this.linetype == 1 ? (this.dataList.length > 10 ? 1 : 0): 0,//设置为 1,表示『隔一个标签显示一个标签』
// margin:15,
textStyle: {
color: '#FFFFFF',
fontSize: 12,
}
},
},
yAxis: {
type: 'value',
name: '公里',
boundaryGap: true,//坐标轴两边留白
// min: 0,
// max: 1500,
// interval: 300,
axisLabel: {
interval: 0,
margin: 2,
textStyle: {
color: '#FFFFFF',
fontSize: 12,
},
},
splitLine: {
lineStyle: {
color: '#ffffff00;',
},
},
grid: {
left: '15%'
},
},
series: [
{
name: 'usecar',
type: 'line',
symbol: "circle",
symbolSize: 0,
itemStyle: {
normal: {
color: '#419fff',
lineStyle: {
color: "#1890FF",
width: 3
},
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
offset: 0,
color: 'rgba(65,159,255,0)'
}, {
offset: 1,
color: 'rgba(65,159,255,0.19)'
}]),
}
}
},
data: this.dataList
},
]
};
this[this.domId].setOption(this.barLineOptions)
},
}
}
</script>
<style scoped lang="scss"></style>