【echart】showLoading hideLoading 無數據時顯示正在加載


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>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM