配置项如下
option = {
grid: {
x: '15%',
y: '25%',
x2: '15%',
y2: '25%'
},
legend: {
x: 'center',
y: '5%',
padding: 0,
itemGap: 20,
data: ['目标销售额', '预测销售额', '实际销售额']
},
tooltip : {
trigger: 'axis',
showDelay: 0,
axisPointer : {
type : 'shadow'
},
formatter: function (params) {
var tip="";
for (var i=0;i<params.length;i++) {
parseInt(params[i].data)>=10000?(params[i].data=(parseInt(params[i].data)/10000).toFixed(2) + "万"):params[i].data;
tip=tip + params[i].seriesName + ":" + params[i].data + '<br/>'
}
return params[0].name.substring(0,4) + "-" + Number(params[0].name.substring(4,6)) + "月" + '<br/>' +tip;
}
},
xAxis: [
{
type: 'category',
data: ['1','2','3'],
axisLine: {
lineStyle: {
color: '#666',
width: 1
}
},
axisLabel: {
formatter: function (value) {
var date = new Date(value.substring(0,4) + "/" + value.substring(4,6) + "/01");
return (date.getMonth() + 1) + '月';
}
}
}
],
yAxis: [{
type: 'value',
splitNumber : 4,
axisLine: {
lineStyle: {
color: '#666',
width: 1
}
},
axisLabel: {
formatter: function (value) {
if (value >= 100000000) {
return value / 100000000 + "亿"
} else if (value >= 10000) {
return value / 10000 + "万";
} else {
return value;
}
}
}
}],
series : [
{
name: '目标销售额',
type: 'bar',
barWidth: 16,
barCategoryGap: '50%',
data: [12,32,44],
itemStyle: {
normal: {color: '#ff804e', barBorderRadius: [4, 4, 0, 0]}
}
},
{
name: '预测销售额',
type: 'bar',
barWidth: 16,
data: [12,32,44],
itemStyle: {
normal: {color: '#feb501', barBorderRadius: [4, 4, 0, 0]}
}
},
{
name: '实际销售额',
type: 'bar',
barWidth: 16,
data: [12,32,44],
itemStyle: {
normal: {color: '#87cffa', barBorderRadius: [4, 4, 0, 0]}
}
}
]
};