methods 方法
// 订单Echarts drawOrder () { this.charts = echarts.init(document.getElementById('order')) // 绘制图表 this.charts.setOption({ title: { text: '', subtext: '', left: 'center' }, tooltip: { trigger: 'item', }, // legend: { // orient: 'horizontal', // left: 'top', // data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎'] // }, series: [ { name: '订单数量', type: 'pie', radius: '70%', center: ['50%', '60%'], data: [ { value: 335, name: '直接访问' }, { value: 310, name: '邮件营销' }, { value: 234, name: '联盟广告' }, { value: 135, name: '视频广告' }, { value: 1548, name: '搜索引擎' } ], emphasis: { itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ] }); },
自适应
在需要window.onresize的函数内直接使用echarts.init()去取:
mounted () { this.$nextTick(function () { // 图表自适应 window.onresize = function () { echarts.init(document.getElementById("order")).resize(); echarts.init(document.getElementById("ranking")).resize(); }; this.drawOrder() this.drawRanking() }); },
借鉴:https://www.pianshen.com/article/5586274051/