LineCharts.vue
1.25 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
<template>
<div :id="domId" style="width: 100%" :style="{ height }"></div>
</template>
<script type="text/ecmascript-6">
import * as echarts from 'echarts'
import getLineOptions from './LineOptions'
export default {
name: 'LineCharts',
props: {
height: {
type: String
},
dataList: {
type: Array,
default: () => []
},
domId: {
type: String,
default: 'line'
},
tooltipFormatterObj: {
type: Array,
default: () => {}
},
valName: {
type: String,
default: 'val'
}
},
data() {
return {}
},
mounted() {
this.barLineDom = document.getElementById(this.domId)
this[this.domId] = echarts.init(this.barLineDom)
this.chartBindEvent()
this.drawBarLine()
},
methods: {
drawBarLine() {
console.log(this.dataList);
this.barLineOptions = getLineOptions()
this.barLineOptions.series[0].data = this.dataList.map(item => item.val)
},
chartBindEvent() {
// resize
window.addEventListener('resize', () => {
this[this.domId].resize()
})
}
}
}
</script>
<style lang="scss" scoped></style>