LineCharts.vue
2.31 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
<!--
* @Description: 折线图组件
* @Author: huyue
* @Date: 2023-09-06 15:08:05
* @LastEditors: huyue
* @LastEditTime: 2023-09-07 18:02:59
-->
<template>
<div :id="domId" style="width: 100%" :style="{ height }"></div>
</template>
<script type="text/ecmascript-6">
import utils from '../../../utils/util'
import * as echarts from 'echarts'
import getLineOptions from './lineOption.js'
export default {
name: 'LineCharts',
props: {
height: {
type: String
},
// dataList: {
// type: Array,
// default: () => []
// },
domId: {
type: String,
default: 'bar-line'
},
tooltipFormatterObj: {
type: Object,
default: () => {}
},
valName: {
type: String,
default: 'val'
}
},
data() {
return {
dataList: []
}
},
mounted() {
this.barLineDom = document.getElementById(this.domId)
this[this.domId] = echarts.init(this.barLineDom)
this.chartBindEvent()
},
methods: {
tooltipFormatter(obj) {
var _currentItem = this.dataList[obj[0].dataIndex]
var _html = ''
var _txt = `<div><div style="color: #FFFFFF">${_currentItem.statMonth || _currentItem.statDate}</div><div style="display:flex;align-items:center"><div style="width: 4px;height: 4px;background: #FFC200;border-radius: 4px;margin-right: 4px;"></div><div style="color: #fff;">${utils.numAddSymbol(_currentItem[this.valName])}</div></div></div>`
_html += `<div style="backdrop-filter: blur(4px);background-color: #051526;border: 2px solid;border-image: linear-gradient(90deg, #074989, #30DCFF, #074989) 1;padding: 10px;">
${_txt}
</div>`
return _html
},
drawLine(dataList) {
this.dataList = dataList
this.barLineOptions = getLineOptions({ tooltipFormatter: this.tooltipFormatter, seriesData: dataList })
this.barLineOptions.xAxis.data = dataList.map(item => item.statMonth || item.statDate)
this.barLineOptions.series[0].data = dataList.map(item => item[this.valName])
this[this.domId].setOption(this.barLineOptions)
},
chartBindEvent() {
// resize
window.addEventListener('resize', () => {
this[this.domId].resize()
})
}
}
}
</script>
<style lang="scss" scoped></style>