1.要實現的功能當echart無數據時顯示數據加載中!有數據顯示echarts圖形
2.實現步驟(showLoading可根據要求設置樣式)
myChart.showLoading({ text: '數據加載中...', color: '#c23531', textColor: '#ffffc2', maskColor: 'rgba(255, 255, 255, 0)', zlevel: 0 });
3.全部代碼
<template> <div > <div id="top" style="width: 100%;height: 100%" ></div> </div> </template> <script> import {getFlow} from '@/api/dashboard'; export default { name: "TopRightChart", data(){ return{ dataFlow:{}, } }, mounted(){ this.drawLine() }, methods:{ drawLine() { // 基於准備好的dom,初始化echarts實例 var myChart = this.$echarts.init(document.getElementById('top')) myChart.showLoading({ text: '數據加載中...', color: '#c23531', textColor: '#ffffc2', maskColor: 'rgba(255, 255, 255, 0)', zlevel: 0 }); getFlow('60').then(res=>{ this.dataFlow=res.data.data myChart.hideLoading(); myChart.setOption({ xAxis: { data: this.dataFlow.xdata }, series: [{ // 根據名字對應到相應的系列 data: this.dataFlow.deny }] }); }) var option={ xAxis: [ //部分樣式省略 { data:[], } ], series: [ { data: [] //部分樣式省略 } ] } myChart .setOption(option); window.addEventListener("resize", function () { myChart.resize(); }); } } } </script> <style scoped> </style>