line.vue
3.37 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
<template>
<div >
<div :id="id" :style="styleInner"></div>
</div>
</template>
<script>
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入柱状图
require('echarts/lib/chart/line');
// 引入提示框和标题组件
require('echarts/lib/component/tooltip');
require('echarts/lib/component/title');
export default {
name: 'lineChart',
data () {
return {
newVal:undefined,
}
},
props:{
id: {
type: String,
default:'lineChart'
},
optionsInner: {
type: Object,
default:() => {
return {}
}
},
styleInner: {
type: Object,
default:() => {
return {width: '200px', height: '100px'}
}
},
},
computed:{
isOpend(){
return this.$store.getters.sidebar.opened
}
},
watch:{
optionsInner:{
handler(newVal,oldVal){
console.log(newVal,'------------line-------------------newval')
console.log(oldVal,'-------------------------------oldVal')
this.drawLine(newVal);
this.$set(this,'newVal',newVal)
},
deep:true,
},
isOpend(nn,old){
console.log(this.newVal,'drawLine');
// this.drawLine(this.newVal);
}
},
mounted(){
this.drawLine();
},
methods: {
drawLine(data){
console.log(data,'drawLine');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById(this.id),'light');
// 绘制图表
myChart.setOption(this.optionsFunc(data));
window.addEventListener('resize',function(){
myChart.resize()
})
},
optionsFunc(data){
let seriesData,xAxisData;
if(data){
var serData = data&&data.series? data.series[0].data:[]
var serXaxis = data&&data.xAxis?data.xAxis.data:[]
seriesData = serData
var nullLength = serXaxis.length - seriesData.length;
var nullArr = []
for(var i = 0 ;i<nullLength;i++){
nullArr.push('-')
}
xAxisData = [...serXaxis].splice(0,seriesData.length).concat(nullArr)
}else{
seriesData = [0];
xAxisData = [0];
}
return {
grid: {
right: '20',
top: '15',
},
tooltip: {
trigger: 'item',
formatter: "{c}",
backgroundColor:'#5E77FF',
borderColor: 'red',
borderWidth:0,
padding: [5,15],
},
xAxis: {
show: true,
type: 'category',
data: xAxisData,
axisLine:{
lineStyle:{
color: '#808285',
}
},
},
yAxis: {
type: 'value',
show: true,
axisLine:{
lineStyle:{
color: '#808285',
}
},
},
series: [{
data: seriesData,
type: 'line',
symbol:'circle', //这句就是去掉点的
symbolSize: 3,
itemStyle: {
borderColor: '#5E77FF',
color: '#5E77FF',
},
smooth: true,
lineStyle:{
color:'#5E77FF',
width:0,
},
areaStyle: {
color:'#5E77FF',
}
}]
};
},
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>