function createEcharts(ele){ //console.info(xarr.length); var height = document.documentElement.clientHeight + 'px'; var width = document.documentElement.clientWidth-20 + 'px'; $(ele).height(height).width(width); } // 绘制折线图 var myLineChart; function CreateLineEchart(ele,lname,xdata,sdata){ createEcharts(ele) myLineChart=echarts.init(ele); var option={ tooltip:{ trigger: 'axis' }, title : { //text: tname, x: "center", //标题水平方向位置 textStyle: { fontSize:13 } }, toolbox:{ show :true }, calculable :true, xAxis:{ data:xdata }, grid: { left: '1%', right: '5%', bottom: '2%', containLabel: true }, yAxis:[{ name:"y("+lname+")" , type:'value', min:Math.floor(Math.min.apply(null, sdata)-1), max:Math.ceil(Math.max.apply(null, sdata)+1), precision:2, axisLabel:{ formatter:function(value){ //解决原点处带符号问题 if(value==0) { return value; }else{ return value ; } } } }], series:[{ type:'line', name:'', symbol:'none', data:sdata, itemStyle:{ normal:{ lineStyle:{ color:'green' } } } }] }; // 使用刚指定的配置项和数据显示图表。 myLineChart.setOption(option); }