请问如何去掉没有数据的 bar,现在占了位置。
One-line summary [问题简述]
如下图,一年级没有数学数据,但是占用了空间,可以不占用空间吗?

Version & Environment [版本及环境]
- ECharts version [ECharts 版本]: 3.4.0
- Browser version [浏览器类型和版本]:
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36 - OS Version [操作系统类型和版本]: macOS 10.12.3
Expected behaviour [期望结果]
一年级语文跟英语之间没有间距
ECharts option [ECharts配置项]
option = {
legend: {
data: [],
// left:110,
},
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
},
formatter: function(params) {
var html = [];
var category = {};
echarts.util.each(params, function(param) {
// console.log(param)
var serie = option.series[param.seriesIndex];
var subject_name = serie.name,
status = serie.status == '未完成' ? 1 : 2;
if (!category[subject_name]) {
category[subject_name] = {};
}
category[subject_name][status] = param.value;
});
// console.log(category);
echarts.util.each(category, function(cate, key) {
html.push(
'<tr>',
'<td>', key, '</td>',
'<td>', cate[1], '</td>',
'<td>', cate[2], '</td>',
'</tr>'
);
})
return '<table style="" class="tooltip-table"><tbody>' +
'<tr><td></td><td>未完成</td><td>已完成</td></tr>' +
html.join('') +
'</tbody></table>';
}
},
yAxis: {
axisLine: {
lineStyle: {
color: '#ccc'
}
},
axisLabel: {
textStyle: {
color: '#777'
}
}
},
xAxis: [{
name: ' 年级',
nameLocation: 'start',
nameTextStyle: {
fontWeight: 'bold'
},
// position: 'bottom',
offset: 50,
axisLine: {
onZero: false,
show: false
},
axisTick: {
length: 70,
inside: true,
lineStyle: {
color: '#ccc'
}
},
axisLabel: {
inside: true,
},
// inverse: true,
data: ['一年级', '二年级', '三年级', '四年级', '五年级']
}
],
series: [{
name: '语文',
status: '已完成',
type: 'bar',
stack: 'B',
data: [220, 182, 191, 234, 290],
itemStyle: {
normal: {
color: '#87b87f',
}
},
label: {
normal: {
show: true,
position: 'bottom',
textStyle: {
color: '#000'
},
formatter: '语文',
}
}
}, {
name: '语文',
status: '未完成',
type: 'bar',
stack: 'B',
itemStyle: {
normal: {
color: '#fff',
borderColor: '#87b87f',
}
},
data: [120, 82, 91, 34, 90]
}, {
name: '数学',
status: '已完成',
type: 'bar',
stack: 'C',
data: ['-', 182, 191, 234, 290],
itemStyle: {
normal: {
color: '#87b87f',
}
},
label: {
normal: {
show: true,
position: 'bottom',
textStyle: {
color: '#000'
},
formatter: '数学',
}
}
}, {
name: '数学',
status: '未完成',
type: 'bar',
stack: 'C',
data: ['-', 132, 91, 204, 220],
itemStyle: {
normal: {
color: '#fff',
borderColor: '#87b87f',
}
},
}, {
name: '英语',
status: '已完成',
type: 'bar',
stack: 'D',
data: [220, 182, 191, 234, 290],
itemStyle: {
normal: {
color: '#87b87f',
}
},
label: {
normal: {
show: true,
position: 'bottom',
textStyle: {
color: '#000'
},
formatter: '英语',
}
}
}, {
name: '英语',
status: '未完成',
type: 'bar',
stack: 'D',
data: [120, 132, 131, 254, 278],
itemStyle: {
normal: {
color: '#fff',
borderColor: '#87b87f',
}
},
}, ]
}
Other comments [其他信息]
饼图也遇到类似的问题,某个数据值是0时,仍然显示该项的label标签和其视觉引导线,标签数值{{c}}显示0。不知道怎么设置把它去掉。
@CYvonne 你试一试把为 0 的值设置为 '-'
@emitle 解决了,非常感谢~ 请问在官方文档里在哪有写这个设置吗?好像没找到...
@CYvonne 官网是有,但是我也忘了在那里了。设置为 '-', null, undefined 好像都可以
@emitle 设置成不可转成数值类型的字符串都可以⊙o⊙
@CYvonne 然而我的问题还没解决,我已经把没有的数据设置成 '-' 了 😢
没法去掉,只能你把横轴的相应类目也去掉
@pissang 不能把横轴的相应类目也去掉吧,因为其他年级下有相应的数据。这个算一个 bug 吧?
不是 bug,我们不能因为这个类目的数据是 - 就不显示这个类目了,如果你们不需要可以去掉,只要去掉一年级的就可以了
@pissang 按照我上面的 series 其实我已经算去掉了吧?
一年级对应的数学(已完成、未完成,stack 都为C),我已经都设置为 - 了。我觉得 stack 都一样的情况下,如果对应的所有的 series value 都为 - 是不应该占用空间的。
+1 同样的需求,我觉得这种需求很正常的啊,应该支持才对
@wilsoncook 这个问题已经 closed 了,估计他们是不会修复这个问题了。
@pissang 没有太看懂啊,什么叫只要去掉一年级的就可以了,一年级的有数据的啊