求解:echarts 柱状堆叠图设置y轴不以0位起始坐标显示不对
app.title = '堆叠柱状图';
option = {
tooltip : {
trigger: 'axis',
axisPointer : { // 坐标轴指示器,坐标轴触发有效
type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
legend: {
data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎','百度','谷歌','必应','其他']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis : [
{
type : 'category',
data : ['周一','周二','周三','周四','周五','周六','周日']
}
],
yAxis : [
{
type : 'value',
axisTick: {
show: false
},
axisLine: {
show: false
},
min:150,
axisLabel: {
show: true,
formatter: function(value) {
return value + "M";
},
textStyle: {
fontSize: 9
}
}
}
],
series : [
{
name:'邮件营销',
barWidth:40,
type:'bar',
stack: '广告',
data:[320, 332, 301, 164, 190, 230, 210],
itemStyle: {
normal: {
label: {
show: true,
position: "top",
rotate: 30,
color:"#333",
textStyle: {
fontSize: "55%"
},
formatter: ""
}
}
},
},
{
name:'视频广告',
type:'bar',
stack: '广告',
data:[380, 332, 301, 354, 390, 330, 410],
itemStyle: {
normal: {
label: {
show: true,
position: "top",
rotate: 40,
color:"#000",
textStyle: {
fontSize: "75%"
},
formatter: ""
}
}
},
},
]
};
let series = option["series"];
let fun = function(params) {
var data3 = 0;
for (var i = 0, l = series.length; i < l; i++) {
data3 += series[i].data[params.dataIndex];
}
return data3.toFixed(0);
};
//加载页面时候替换最后一个series的formatter
series[series.length - 1]["itemStyle"]["normal"]["label"][
"formatter"
] = fun;