diff --git a/nezha-fronted/src/components/page/dashboard/overview/chart.vue b/nezha-fronted/src/components/page/dashboard/overview/chart.vue index ab56b746b..e881ab054 100644 --- a/nezha-fronted/src/components/page/dashboard/overview/chart.vue +++ b/nezha-fronted/src/components/page/dashboard/overview/chart.vue @@ -96,13 +96,13 @@ if(!this.option){ this.option = chartConfig.getOption(this.chartType); } - if (legend && legendData) { + if (legend && legendData && legendData.length > 0) { legend.formatter = function(name) { let type = legendData.find(item => { return item[0] == name; }); - return `${name} (${type[1]}%)`; - } + return type ? `${name} (${type[1]}%)` : null; + }; this.$set(this.option, "legend", legend); } diff --git a/nezha-fronted/src/components/page/dashboard/overview/overview2.vue b/nezha-fronted/src/components/page/dashboard/overview/overview2.vue index 7e9fb6980..15b58093d 100644 --- a/nezha-fronted/src/components/page/dashboard/overview/overview2.vue +++ b/nezha-fronted/src/components/page/dashboard/overview/overview2.vue @@ -359,13 +359,13 @@ let vm = this; let assetTotalCount = function() { let count = 0; - vm.assetData.typeStat.forEach(item => { + vm.assetData.typeStat && vm.assetData.typeStat.forEach(item => { count += item.total; }); return count; }(); - this.assetData.typeStat.forEach(item => { + vm.assetData.typeStat && this.assetData.typeStat.forEach(item => { legendData.push([item.name, (item.total*100/assetTotalCount).toFixed(2)]); typeSeriesData.push({name: item.name, value: item.total, up: item.pingUp, down: item.pingDown}); }); @@ -430,7 +430,7 @@ right: 25, icon: "circle", }; - this.$refs.assetTypePie.setSeries(series, legend, legendData); + this.assetData.typeStat && this.$refs.assetTypePie.setSeries(series, legend, legendData); this.$refs.assetTypePie.endLoading(); } resolve()