function makeBarae(obj1,obj2, mytitle, mysename, mytype) {
var main = document.getElementById(mytype);
var chart = echarts.init(main);
var option = {
title: {
text: mytitle
},
tooltip: {
show: true
},
legend: {
data:[mysename]
},
toolbox: {
show : false,
feature : {
magicType : {show: true, type: ['line', 'bar']},
restore : {show: true},
saveAsImage : {show: true}
}
},
grid:{
x:'15%',
y:30,
x2:40,
y2:100
},
xAxis : [
{
type : 'category',
boundaryGap : true,
axisLabel: {
interval:0 ,
formatter : function(params){
var newParamsName = "";
var paramsNameNumber = params.length;
var provideNumber = 4;
var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
if (paramsNameNumber > provideNumber) {
for (var p = 0; p < rowNumber; p++) {
var tempStr = "";
var start = p * provideNumber;
var end = start + provideNumber;
if (p == rowNumber - 1) {
tempStr = params.substring(start, paramsNameNumber);
} else {
tempStr = params.substring(start, end) + "\n";
}
newParamsName += tempStr;
}
} else {
newParamsName = params;
}
return newParamsName
}
},
data : obj1
}
],
yAxis : [
{
type : 'value'
}
],
series : [
{
"name":"数量",
"type":"bar",
itemStyle: {
normal: {
label: {
show: true,
textStyle: {
color: '#800080'
}
}
}
},
"data":obj2
}
]
};
// 为echarts对象加载数据
chart.setOption(option);
}