lineChart.vue
2.34 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
<template>
<div class="chart-box">
<div class="chart-line" id="line"></div>
</div>
</template>
<script>
import * as echarts from 'echarts'
export default {
name: 'LineChart',
props: ['list'],
data() {
return {
option: {
tooltip: {
trigger: 'axis',
// formatter: `{b}\r \n成交金额:{c}\n \n 订单总数:{d}单`
formatter: function(params) {
var tips = ''
if (params != null && params.length > 0) {
tips += params[0].name + '<br />'
for (var i = 0; i < params.length; i++) {
params[i].marker = '<span style="display:inline-block;margin-right:4px;border-radius:10px;width:10px;height:10px;background-color:#5850FF;"></span>'
tips += params[i].marker + '成交金额: ' + params[i].value + '元'
}
}
return tips
// var res = `<div>${params[0].name}</div>
// <div>成交金额:${params[0].data}元</div>
// <div>订单总数:${params[0].value}</div>`
// return res
}
},
xAxis: {
type: 'category',
data: []
},
yAxis: {
type: 'value'
},
// legend: {
// height: 260,
// width: 1184
// },
grid: {
x: 80,
y: 20,
x2: 30,
y2: 40
},
series: [
{
data: [],
type: 'line',
itemStyle: {
normal: {
lineStyle: {
color: '#5850FF' // 改变折线颜色
}
}
}
}
]
},
myChart: {}
}
},
watch: {
list(val) {
const xData = val.map(i => i.dataDateStr)
const yData = val.map(i => i.amount)
this.option.xAxis.data = xData
this.option.series[0].data = yData
this.option.series[0].count = val.map(i => i.count)
this.option && this.myChart.setOption(this.option)
}
},
methods: {},
mounted() {
let chartDom = document.getElementById('line')
this.myChart = echarts.init(chartDom)
// this.option && this.myChart.setOption(this.option)
}
}
</script>
<style lang="scss" scoped>
.chart-box {
height: 196px;
width: 100%;
}
.chart-line {
height: 196px;
}
</style>