正常官网上的代码实现的效果
option = {
tooltip: {
trigger: 'axis',
axisPointer: {
// Use axis to trigger tooltip
type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
}
},
legend: {},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'value'
},
yAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', ]
},
series: [
{
name: 'Direct',
type: 'bar',
stack: 'total',
label: {
show: true
},
emphasis: {
focus: 'series'
},
data: [320,0,0,0]
},
{
name: 'Mail Ad',
type: 'bar',
stack: 'total',
label: {
show: true,
},
emphasis: {
focus: 'series'
},
data: [0,120,0,0]
},
{
name: 'Affiliate Ad',
type: 'bar',
stack: 'total',
label: {
show: true
},
emphasis: {
focus: 'series'
},
data: [0,0,191,0]
},
]
};
找过很多方法都显示不了(我觉得是版本的原因,有大佬知道什么原因可以留言,非常感谢!)
最后series修改成这样能实现
series:[
{
name: item.value, type: 'bar', stack: 'total', barWidth : '50%',//柱图宽度 itemStyle:{ normal:{ label: { show : true, position : 'inside', formatter : function (params) { if(params.value < 0){ //为0时不显示 return '' }else{ return params.value } }, textStyle : { color: '#fff' } } }, }, emphasis: { focus: 'series' }, data: arr}
]