xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

v-charts no data All In One

v-charts no data All In One

echarts dispose

    async getData () {
        this.chartLoading = true;
        this.dataEmpty = false;
        const params = this.getParams();
        const res = await apiService[this.pieApi](params).finally(() => {
            this.chartLoading = false;
        });
        const {data, key, value} = res.data.data;
        // this.$refs.chart.echarts.resize();
        this.chartData = Object.assign({}, {
            columns: [key, value],
            rows: this.formatRows(data),
        });
        if (!data.length) {
            this.chartData.columns = [];
            this.chartData.rows = [];
            // this.$refs.chart.echarts.dispose();
            console.log('this.$refs.chart', this.$refs.chart);
            console.log('this.$refs.chart.echarts', this.$refs.chart.echarts);
            this.$refs.chart.init();
            this.$refs.chart.clean();
            // const id = this.$refs.chart.echarts.id;
            // const div = document.querySelector(`[_echarts_instance_="${id}"]`);
            // div.style.display = 'none';
            // this.$refs.chart.echarts.setOption({series: []}, true);
            // this.$refs.chart.echarts.resize();
            // this.chartExtend.series = [];
            // this.chartSettings.series = [];
            // this.chartSettings.setOptionOpts = true;
            // this.chartSettings['set-option-opts'] = true;
            this.dataEmpty = true;
            return;
        }
        // document.getElementById('e1').removeAttribute('_echarts_instance_');
        // this.$nextTick(_ => {
        //     this.$refs.chart.echarts.resize();
        // });
    },

v-charts 重绘



echarts setOption

set-option-opts

https://sunra.top/2020/03/13/v-charts/

bug

destroy

clear series

// this.chartData.columns = [];
// this.chartData.rows = [];

// this.chartExtend.series = [];
// this.chartSettings.series = [];

this.$refs.chart.echarts.setOption({series: []}, true);

solution

CSS show / hidden ✅

    async getData () {
        this.chartLoading = true;
        this.dataEmpty = false;
        const params = this.getParams();
        const res = await apiService[this.pieApi](params).finally(() => {
            this.chartLoading = false;
        });
        const {data, key, value} = res.data.data;
        this.chartData = Object.assign({}, {
            columns: [key, value],
            rows: this.formatRows(data),
        });
        const id = this.$refs.chart.echarts.id;
        const div = document.querySelector(`[_echarts_instance_="${id}"]`);
        div.style.display = 'block';
        if (!data.length) {
            // this.chartData.columns = [];
            // this.chartData.rows = [];
            div.style.display = 'none';
            this.dataEmpty = true;
            return;
        }
    },

refs

https://v-charts.xgqfrms.xyz/#/props-demo2

https://www.runoob.com/echarts/echarts-ajax-data.html



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-01-14 00:07  xgqfrms  阅读(44)  评论(7编辑  收藏  举报