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
| <template>
| <div class="echarts" ref="echarts"></div>
| </template>
|
| <script>
| import * as echarts from 'echarts'
| export default {
| name: 'SmoothLineEcharts',
| props: ['data'],
| data() {
| return {
| opt: {},
| echarts: {}
| }
| },
| mounted() {
| this.createChart()
| this.changeEcharts()
| },
| methods: {
| createChart() {
| this.echarts = echarts.init(this.$refs.echarts)
| this.opt = {
| grid: {
| left: '60px',
| right: '10px'
| },
| tooltip: {
| show: true,
| trigger: 'axis',
| backgroundColor: 'rgba(0,0,0,.65)',
| padding: 10,
| textStyle: {
| color: '#fff'
| },
| axisPointer: {
| type: 'none'
| },
| formatter: '{b0}<br /><span style="display:inline-block;width:10px;height:10px;background-color:#1e9fff;margin-right:2px"></span>{a0}<span style="display:inline-block;width:20px;x"></span>{c0}%'
| },
| xAxis: {
| type: 'category',
| data: [],
| boundaryGap: false,
| axisTick: false,
| axisLabel: {
| margin: 20,
| color: '#000'
| },
| axisLine: {
| lineStyle: {
| color: '#ccebff'
| }
| }
| },
| yAxis: {
| type: 'value',
| name: '(%)',
| nameTextStyle: {
| align: 'right',
| padding: [5, 10],
| color: '#000'
| },
| axisLabel: {
| color: '#000',
| margin: 15
| },
| splitLine: {
| lineStyle: {
| type: 'dashed',
| color: '#ccebff'
| }
| }
| },
| series: [
| {
| data: [],
| type: 'line',
| smooth: true,
| symbol: 'none',
| name: '',
| lineStyle: {
| color: ''
| }
| }
| ]
| }
| this.echarts.setOption(this.opt)
| },
| changeEcharts() {
| this.opt.xAxis.data = this.data.xAxisData
| this.opt.series[0].data = this.data.yAxisData
| this.opt.series[0].name = this.data.name
| this.opt.series[0].lineStyle.color = this.data.color
| this.echarts.setOption(this.opt)
| }
| },
| watch: {
| data: {
| handler(val) {
| this.changeEcharts()
| }
| }
| }
| }
| </script>
|
| <style lang="less" scoped>
| .echarts {
| width: 100%;
| height: 300px;
| }
| </style>
|
|