var eap_chart_cfg = { bgColor:'#F7F7F7', color:['#F9758F','#36C8CA', '#B6A2DE', '#FFB980','#5AB1EF','#97B552', '#D19392', '#8D98B3','#6e7074', '#546570', '#c4ccd3'] }; $.extend({ getEchartObj:function(_id){ return echarts.getInstanceByDom(document.getElementById(_id)); }, getFullCanvasDataURL:function(divId){ var baseCanvas = $("#"+divId).find("canvas").first()[0]; if(!baseCanvas){ return false; }; var width = baseCanvas.width; var height = baseCanvas.height; var ctx = baseCanvas.getContext("2d"); //遍历,将后续的画布添加到在第一个上 $("#"+divId).find("canvas").each(function(i,canvasObj){ if(i>0){ var canvasTmp = $(canvasObj)[0]; ctx.drawImage(canvasTmp,0,0,width,height); } }); //获取base64位的url return baseCanvas.toDataURL(); }, getChartImage:function(_id,opts){ var myChart = echarts.getInstanceByDom(document.getElementById(_id)); if(myChart){ if(!opts){ opts = {pixelRatio: 1}; } return myChart.getDataURL(opts); } }, quickajax:function(url,data,callback){ $.cuajax({ url:url, method:"post", timeout:WDK_Timeout, data:data, success:function(result) { var jparam = $.str2json(result); callback(jparam); }, error:function(result){ } }); }, pie:function(jparam){ var _id = jparam.id?jparam.id:''; var _data = jparam.data?jparam.data:undefined; var _idField = jparam.idField?jparam.idField:'value'; var _textField = jparam.textField?jparam.textField:'name'; //{a}(系列名称),{b}(数据项名称),{c}(数值), {d}(百分比) var _formatter = jparam.formatter?jparam.formatter:'{a}
{b} : {c} ({d}%)'; var _url = jparam.url?jparam.url:WDK_URL; var _sclae = jparam.sclae?jparam.sclae:2; var _queryParams = jparam.queryParams?jparam.queryParams:{}; var _beforeRender = jparam.beforeRender?jparam.beforeRender:undefined; var _top = jparam.top?jparam.top:'50%'; var _labelformatter = jparam.labelFormatter?jparam.labelFormatter:'{b}\n {d}%'; if(_data){ pieRender(getPieData(_data)); }else{ if(_url){ $.quickajax(_url,_queryParams,function(jparam){ pieRender(getPieData(jparam)); }); } } /** * [getPieData 加工饼图需要的数据] * @param {[type]} srcData [原始数据] * @return {[type]} [加工后的饼图数据] */ function getPieData(_srcData){ var srcData = _srcData; if(_beforeRender){ srcData = _beforeRender.call(jparam,_srcData); } var newData = []; for(var i=0;i0){ for(var i=0;i 0){ opts.xAxis.axisLabel = { interval:0, rotate:_rotate//文本旋转 } } if(!(jparam.hidelegend == '1')){ opts.legend = { orient: 'horizontal',//vertical left: 'center', top: 'bottom', data:legendData }; if(jparam.legend_left){ opts.legend.left = jparam.legend_left; } if(jparam.legend_top){ opts.legend.top = jparam.legend_top; } } if(!(jparam.hidetoolbox == '1')){ opts.toolbox = { show : true, feature : { /*dataView : {show: true, readOnly: false},*/ magicType : {show: true, type: ['line', 'bar']}, restore : {show: true} /*,saveAsImage : {show: true}*/ } }; } chart.setOption(opts); }else{ var option = chart.getOption(); if(titleParam && titleParam.text){ option.title = titleParam; } if(!(jparam.hidelegend == '1')){ option.legend.data = legendData; } option.series = seriesData; chart.setOption(option); } } } });