Commit d5a450f8 by 前端

当data为空时,设置默认的X轴和Y轴,但不包含数据点

1 parent 806c8897
......@@ -45,12 +45,23 @@ export default {
drawChart() {
const chart = echarts.init(this.$refs.barChart);
let xAxisData, seriesData;
if (this.data && this.data.length > 0) {
xAxisData = this.data.map(item => item.name);
seriesData = this.data.map(item => item.value);
} else {
// 当data为空时,设置默认的X轴和Y轴,但不包含数据点
xAxisData = [''];
seriesData = [0];
}
const option = {
xAxis: {
type: 'category',
data: this.data.map(item => item.name),
axisTick: { show: false },
axisLine: { show: false },
axisLine: { show: true },
axisLabel: {
interval: 0,
rotate: this.rotate
......@@ -65,7 +76,7 @@ export default {
// axisLabel: { show: false }
},
series: [{
data: this.data.map(item => item.value),
data: seriesData,
type: 'bar',
barWidth: '20%',
label: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!