//Echart放入容器
<div id="barEchart" style="width:100%;height:50%"></div>
//初始化Echart
var barEchart = echarts.init(document.getElementById("barEchart"));
//Echart集合
function creatBarEchart() {
option = {
//小标题
title: {
text: ''
},
//鼠标聚焦时的提示框
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow', //默认为直线[y轴线触发->line(默认);y轴块状触发->shadow]
},
formatter: '{b} </br>{a}:{c}</br>{a1}:{c1}%</br>'//formatter: '{b} </br>{a}:{c}</br>{a1}:{c1}</br>'
},
grid: {
top: '60px',
left: '10px',
right: '20px',
bottom: '50px',
containLabel: true,
},
//图例的含义
legend: {
data: ['覆盖家数','覆盖率'],
x: 'center', //left center
y: 'bottom', //center
},
//x轴
xAxis: {
data: xTitleArray
},
//y轴?
yAxis: [{
name: '家数',
type: 'value'
},
//右侧Y轴
{
name: '增长率',
type: 'value',
axisLabel: {
show: true,
formatter: '{value}%'
},
splitLine: {
show: false
}
}],
dataZoom: [{
id: 'dataZoomX',
type: 'inside',
//设置x轴缩放比例
start: 0, //x轴起始位置
end: 15, //显示比例
},{
id: 'dataZoomY',
type: 'inside'
}],
series: [{
name: '覆盖家数',
type: 'bar',
stack: 'one',
data: coverArray,
barMaxWidth: 45,
label: {
normal: {
position: 'top',
show: true,
color:'rgb(1,1,1)',
formatter:function(param){
console.log(param);
return "第" + (parseInt(param.dataIndex)+1).toString() + "名"
}
}
}
}]
};
barEchart.setOption(option, true);
}
//echart横竖屏的适配
window.onresize = function() {
barEchart.resize();
}