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
| <template>
| <l-echart ref="chart" @finished="init"></l-echart>
| </template>
|
| <script>
| import * as echarts from 'echarts'
| import lEchart from "@/components/lime-echart/components/l-echart/l-echart.vue"
|
| const mychart = null
| export default {
| components: {
| lEchart
| },
| name: "echart",
| props: {
| option: {
| type: Object
| },
| initId: {
| type: String
| },
| width: {
| type: String,
| default: "700rpx"
| },
| height: {
| type: String,
| default: "500rpx"
| }
| },
| data() {
| return {
| myChart: null,
| }
| },
| watch: {
| 'option': {
| handler(newVal, oldVal) {
| if (newVal) {
| this.init()
| }
| },
| deep: true,
| }
| },
| methods: {
| async init() {
|
| if (this.option) {
| // chart 图表实例不能存在data里
| const chart = await this.$refs.chart.init(echarts);
| setTimeout(() => {
| chart.setOption(this.option)
| }, 500)
| }
| },
|
| async initOption(option) {
| // chart 图表实例不能存在data里
| const chart = await this.$refs.chart.init(echarts);
| setTimeout(() => {
| chart.setOption(option)
| }, 500)
| },
|
| }
| }
| </script>
|
|
| <style scoped lang="scss">
| </style>
|
|