//autoLoadChart("barAndLine", "chartDiv", xName, hjNumber,lvNumber);
function autoLoadChart(chartType, id, xName, hjNumber,lvNumber) {
var chartDiv = document.getElementById(id);
var myChart = echarts.getInstanceByDom(chartDiv);
if (typeof (myChart) != ‘undefined’) {
myChart.dispose();
}
// 用于使chart自适应高度和宽度,通过窗体高宽计算容器高宽
var resizeWorldMapContainer = function() {
chartDiv.style.width = document.getElementById(id).offsetWidth + ‘px’;
chartDiv.style.height = document.getElementById(id).offsetHeight + ‘px’;
}
// 设置容器高宽
resizeWorldMapContainer();
myChart = echarts.init(chartDiv);
var option = {};
if(chartType == “barAndLine”){
option = this.getLineAndBarOption(xName,hjNumber,lvNumber);
}
myChart.setOption(option);
// 用于使chart自适应高度和宽度
window.onresize = function() {
// 重置容器高宽
resizeWorldMapContainer();
myChart.resize();
};
var _self = this;
myChart.on(‘click’, function(param) {
});
}
function getLineAndBarOption(xName,hjNumber,lvNumber) {
option = {
tooltip : {
formatter : ‘{b} : {c}个’,
trigger : ‘axis’,
axisPointer : {
type : ‘cross’,
label: {
backgroundColor: ‘#FFC000’,
color : ‘#ccc’
}
}
},
grid: {
left: 10,
right: 10,
bottom: 25,
top : 45,
containLabel: true
},
legend : {
data : [ ‘合计’,‘按期闭环率’ ],
textStyle : {
color : “#ccc”
}
},
xAxis : [ {
type : ‘category’,
axisTick : {
alignWithLabel : true
},
axisLine : {
lineStyle : {
color : ‘#ccc’
}
},
axisLabel : {
interval : 0,
rotate : 50
},
data : xName
} ],
yAxis : [ {
type : ‘value’,
name : ‘合计’,
position : ‘left’,
axisLabel : {
formatter : ‘{value}/个’
},
axisLine : {
lineStyle : {
color : ‘#ccc’
}
}
}, {
type : ‘value’,
name : ‘按期闭环率’,
position : ‘right’,
axisLabel : {
formatter : ‘{value}%’
},
splitLine: {//设置去掉一边的坐标轴刻度线
show: false
},
axisLine : {
lineStyle : {
color : ‘#ccc’
}
}
} ],
dataZoom: [{
show: true,
height: 20,
xAxisIndex: [
0
],
bottom:0,
start: 0,
end: 60,
textStyle : {
color : “#ccc”,
fontWeight : ‘lighter’
}
},
{
type: “inside”,
show: true,
height: 15,
xAxisIndex: [
0
],
start: 0,
end: 60
}
],
series : [ {
name : ‘合计’,
type : ‘bar’,
itemStyle : {
normal : {
color : ‘#FF6600’
}
},
yAxisIndex : 0,
data : hjNumber
},
{
name : ‘按期闭环率’,
symbol:‘diamond’,//虚点变实点
type : ‘line’,
itemStyle : {
normal : {
color : ‘#FFC000’
}
},
yAxisIndex : 1,
data : lvNumber
}]
};
return option;
}