后台dom拼接xml,动态显示统计图
Posted 根目录97
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了后台dom拼接xml,动态显示统计图相关的知识,希望对你有一定的参考价值。
1 这个东西让我好生头疼,贴代码吧 2 3 // 两秒后模拟点击 4 setTimeout(function() { 5 // IE 6 if(document.all) { 7 document.getElementById("userQuery").click(); 8 }// 其它浏览器 9 else { 10 var e = document.createEvent("MouseEvents"); 11 e.initEvent("click", true, true); 12 document.getElementById("userQuery").dispatchEvent(e); 13 } 14 }, 1000); 15 $("#userQuery").click(function(){ 16 var $this = $(this); 17 var companyCode=GetRequest()[‘companyCode‘]; 18 $("#compAny").val(companyCode); 19 //将queryStr传到后台,进行获取数据 20 var queryStr = $this.parents(‘form‘).serialize(); 21 $.ajax({ 22 url: "../../userliebiao/userGraph.do", 23 data: queryStr, 24 type: "post", 25 cache:false, 26 dataType: "json", 27 success: function (data) { 28 var myChart; 29 myChart = new FusionCharts("../../fusionCharts/Line.swf","myChartId", "1200", "400", "0" ); 30 myChart.setDataXML(data.xml); //调用后台的xml数据 31 myChart.render("userPic"); //将数据送给div 进行显示},//如果后台有错 32 error: function(XMLHttpRequest, textStatus, errorThrown) { 33 console.log(XMLHttpRequest.status); //一切正常 200 34 alert(XMLHttpRequest.status); 35 console.log(XMLHttpRequest.readyState); 36 //此阶段确认全部数据都已经解析为客户端可用的格式,解析已经完成。值为4表示数据解析完毕,可以通过XMLHttpRequest对象的相应属性取得数据。 37 alert(XMLHttpRequest.readyState); 38 console.log(textStatus); 39 alert("出错了"+textStatus);}}); }); 40 41 后台方法: 42 43 try { 44 String subcaption = null; 45 User user=new User(); 46 String type=this.getParam("cycle"); 47 if (type.equals("1")) { 48 type="1,2"; //1:按天 49 user.setDmType(type); 50 }else if(type.equals("2")){ 51 type="4,2"; //1:按月 52 user.setDmType(type); 53 }else if(type.equals("3")){ 54 type="8,3"; //1:按年"minZu" 55 user.setDmType(type); 56 } 57 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 58 String allTime=this.getParam("fcreatetime2"); 59 String compAny=this.getParam("compAny"); 60 Map<String, Object> map = new HashMap<String, Object>(); 61 if (allTime!=null || allTime!="") { 62 String[] a=allTime.split(" 至 "); //将时间分割为开始时间~结束时间 63 String betime=a[0]; 64 String entime=a[1]; 65 subcaption=betime+" 至 "+entime; 66 Date time1 = sdf.parse(betime); 67 Date time2 = sdf.parse(entime); 68 if (type!=""||compAny!="") { 69 user.setDmType(type); 70 user.setCompanyCode(compAny); 71 } 72 map.put("dmType",user.getDmType()); //将数据存到map,作为sql方法的参数 73 map.put("companycode",user.getCompanyCode()); 74 map.put("beginTime",time1); 75 map.put("overTime", time2); 76 } 77 List<Map> aa = los.userGraph(map);//执行sql语句 78 Document document = DocumentHelper.createDocument();//创建dom节点 79 // if(!"3".equals(map.get("querytype").toString())){//如果不是按地区查询 80 // String yAxisMaxValue="50000"; //y轴最大值 81 String xAxisName="注册日期"; 82 String yAxisName="注册人数"; 83 String numberSuffix="人"; //数字的后缀 84 String xlable; 85 86 String title = "登录人次统计"; 87 Element root = XmlDom4jUtils.addElementAndAttribute(document, "chart", 88 "caption","注册人数统计 ","xAxisName","注册日期 ","yAxisName","注册人数", 89 "yAxisMinValue","200","showValues","","alternateHGridColor", 90 "FCB541","alternateHGridAlpha","20","divLineColor","FCB541","divLineAlpha","50", 91 "canvasBorderColor","666666","baseFontColor","666666","lineColor","FCB541", 92 "baseFont","Arial","baseFontSize","15","rotateYAxisName","0", 93 "chartRightMargin","50","showBorder","0", 94 "canvasBorderThickness ","1","showNames","", 95 "numDivLines ","4", 96 "numberSuffix",numberSuffix, 97 // "xAxisName",xAxisName, 98 "subcaption",subcaption+" ", 99 "showAlternateHGridColor","1", 100 "canvasBorderColor","FFCCCC", 101 "bgColor","FFFFFF,FFFFFF", 102 "anchorRadius","2",//折线节点半径 103 "bgColor","FFFFFF" 104 ); 105 String ss; 106 for (Map map2 : aa) { 107 ss=(String) map2.get("CREATEDDATE"); 108 boolean a = ss.contains("月"); 109 if (a!=true) { 110 if (type.equals("1,2")) { 111 ss+="日"; 112 } 113 if (type.equals("4,2")) { 114 ss+="月"; 115 } 116 if (type.equals("8,3")) { 117 ss+="年"; 118 } 119 } 120 map2.put("CREATEDDATE", ss); 121 XmlDom4jUtils.addChildrenAndAttribute(root,"set","label",""+map2.get("CREATEDDATE")+"","value",""+map2.get("VISITORID")+""); 122 } 123 124 Element styles = XmlDom4jUtils.addChildren(root, "styles"); 125 Element definition = XmlDom4jUtils.addChildren(styles,"definition"); 126 XmlDom4jUtils.addChildrenAndAttribute(definition,"style","name","Anim1","type","animation","param","_xscale","start","0","duration","1"); 127 XmlDom4jUtils.addChildrenAndAttribute(definition,"style","name","Anim2","type","animation","param","_alpha","start","0","duration","0.6"); 128 Element application = XmlDom4jUtils.addChildren(styles,"application"); 129 XmlDom4jUtils.addChildrenAndAttribute(application,"apply","toObject","DIVLINES","styles","Anim1"); 130 XmlDom4jUtils.addChildrenAndAttribute(application,"apply","toObject","HGRID","styles","Anim2"); 131 XmlDom4jUtils.addChildrenAndAttribute(application,"apply","toObject","DATALABELS","styles","DataShadow,Anim2"); 132 133 Map<String, Object> mapp = new HashMap<String, Object>(); 134 mapp.put("xml", document.asXML()); 135 String json = JsonUtils.mapToJson(mapp); 136 outStringData(json); 137 } catch (ParseException e) { 138 e.printStackTrace(); 139 } 140 141 核心是sql语句: 142 143 select count(i.createddate) as visitorId,substr(u.createddate,${dmType}) as createddate 144 from ** u,// i 145 where u.userinfoids = i.ids 146 <if test="beginTime !=null and beginTime !=‘‘"> 147 <![CDATA[ 148 and substr(u.createddate,0,10) >= #{beginTime} 149 ]]> 150 </if> 151 <if test="overTime !=null and overTime !=‘‘"> 152 <![CDATA[ 153 and substr(u.createddate,0,10) <= #{overTime} 154 ]]> 155 </if> 156 <if test="companycode !=null and companycode !=‘‘"> 157 and u.COMPANYCODE = #{companycode} 158 </if> 159 <![CDATA[ 160 group by substr(u.createddate, ${dmType}) 161 order by substr(u.createddate, ${dmType}) asc 162 ]]> 163 164 dao代码: 165 166 //图形统计 167 public List<Map> **(Map<String, Object> map){ 168 // super.sqlSessionTemplate.selectMap("路径", map); 169 return super.sqlSessionTemplate.selectList("路径", map); 170 171 }
以上是关于后台dom拼接xml,动态显示统计图的主要内容,如果未能解决你的问题,请参考以下文章
easyui datagrid 动态拼接columns以及赋值
在.NET MVC 中使用Highcharts+Ajax+Json生成动态曲线图,柱状图,饼图