admin
2024-04-24 363457b34e0e4f26ffe51aa80ecb227bf7873308
提交 | 用户 | 时间
363457 1 <template>
A 2   <div :class="className" :style="{height:height,width:width}" />
3 </template>
4
5 <script>
6 import * as echarts from 'echarts'
7 require('echarts/theme/macarons') // echarts theme
8 import resize from './mixins/resize'
9
10 export default {
11   mixins: [resize],
12   props: {
13     className: {
14       type: String,
15       default: 'chart'
16     },
17     width: {
18       type: String,
19       default: '100%'
20     },
21     height: {
22       type: String,
23       default: '300px'
24     }
25   },
26   data() {
27     return {
28       chart: null
29     }
30   },
31   mounted() {
32     this.$nextTick(() => {
33       this.initChart()
34     })
35   },
36   beforeDestroy() {
37     if (!this.chart) {
38       return
39     }
40     this.chart.dispose()
41     this.chart = null
42   },
43   methods: {
44     initChart() {
45       this.chart = echarts.init(this.$el, 'macarons')
46
47       this.chart.setOption({
48         tooltip: {
49           trigger: 'item',
50           formatter: '{a} <br/>{b} : {c} ({d}%)'
51         },
52         legend: {
53           left: 'center',
54           bottom: '10',
55           data: ['Industries', 'Technology', 'Forex', 'Gold', 'Forecasts']
56         },
57         series: [
58           {
59             name: 'WEEKLY WRITE ARTICLES',
60             type: 'pie',
61             roseType: 'radius',
62             radius: [15, 95],
63             center: ['50%', '38%'],
64             data: [
65               { value: 320, name: 'Industries' },
66               { value: 240, name: 'Technology' },
67               { value: 149, name: 'Forex' },
68               { value: 100, name: 'Gold' },
69               { value: 59, name: 'Forecasts' }
70             ],
71             animationEasing: 'cubicInOut',
72             animationDuration: 2600
73           }
74         ]
75       })
76     }
77   }
78 }
79 </script>