java端获取数据代码
?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
-
????public?String?CreateCasePorjectDibtXmlData(TestCase?searchtc,String?caption,?String?subCaption,?
-
????????????String?baseFontSize,?boolean?ISCreateFile,?String?pFileName)?{ ?
- ???????? ?
- ???????? ?
-
?????????
-
?????????????
-
?????????
-
????????CaseReportService?cs?=?new?CaseReportService(); ?
- ???????? ?
- ????????List<DisCaseProject>?ldcp?=?cs.getDisCaseProjectData(searchtc); ?
-
????????int?ListSize?=?ldcp.size(); ?
- ????????Document?document?=?DocumentHelper.createDocument(); ?
-
????????Element?root?=?document.addElement("graph").addAttribute("caption",?
-
????????????????caption).addAttribute("baseFontSize",?baseFontSize) ?
-
????????????????.addAttribute("showNames",?"1").addAttribute( ?
-
????????????????????????"decimalPrecision",?"0").addAttribute( ?
-
????????????????????????"formatNumberScale",?"0").addAttribute("yAxisMinValue",?
-
????????????????????????"0"); ?
-
????????if?(subCaption?!=?null)?{ ?
-
????????????root.addAttribute("subCaption",?subCaption); ?
- ????????} ?
-
????????int?totalCaseCount?=?0; ?
- ???????? ?
- ????????Iterator<DisCaseProject>?its?=?ldcp.iterator(); ?
-
????????while?(its.hasNext())?{ ?
- ????????????DisCaseProject?Temp_CaseCount?=?its.next(); ?
-
????????????if?(Temp_CaseCount?==?null) ?
-
????????????????break; ?
- ????????????totalCaseCount?=?totalCaseCount?+?Temp_CaseCount.getCount(); ?
- ????????} ?
- ???????? ?
-
????????if?(ListSize?>?com.help.Colordef.colorCount)?{ ?
-
????????????String?color[]?=?new?String[ListSize]; ?
-
????????????for?(int?i?=?0;?i?<?ListSize;?i++)?{ ?
-
????????????????double?n?=?Math.random(); ?
-
????????????????double?m?=?Math.random(); ?
-
????????????????double?k?=?Math.random(); ?
-
????????????????int?j?=?(int)?(n?*?m?*?k?*?0xFFFFFF); ?
- ????????????????color[i]?=?Integer.toHexString(j); ?
- ????????????} ?
- ????????????Iterator<DisCaseProject>?it?=?ldcp.iterator(); ?
- ?
-
????????????int?iColor?=?0; ?
-
????????????while?(it.hasNext())?{ ?
- ????????????????DisCaseProject?temp?=?it.next(); ?
-
????????????????if?(temp?==?null) ?
-
????????????????????break; ?
-
????????????????root.addElement("set").addAttribute( ?
-
????????????????????????????????"name",?
- ????????????????????????????????temp.getProjectname() ?
-
????????????????????????????????????????+?":"?
-
????????????????????????????????????????+?(int)?(((float)?temp.getCount()/(float)totalCaseCount)?*?100) ?
-
????????????????????????????????????????+?"%").addAttribute("value",?
- ????????????????????????????????Integer.toString(temp.getCount())) ?
-
????????????????????????.addAttribute("color",?color[iColor]); ?
- ????????????????iColor++; ?
- ????????????} ?
-
????????}?else?{ ?
- ????????????Iterator<DisCaseProject>?it?=?ldcp.iterator(); ?
- ?
-
????????????int?iColor?=?0; ?
-
????????????while?(it.hasNext())?{ ?
- ????????????????DisCaseProject?temp?=?it.next(); ?
-
????????????????if?(temp?==?null) ?
-
????????????????????break; ?
- ?
- ????????????????root ?
-
????????????????????????.addElement("set") ?
- ????????????????????????.addAttribute( ?
-
????????????????????????????????"name",?
- ????????????????????????????????temp.getProjectname() ?
-
????????????????????????????????????????+?":"?
-
????????????????????????????????????????+?(int)?(((float)?temp.getCount()/?(float)?totalCaseCount)?*?100) ?
-
????????????????????????????????????????+?"%") ?
-
????????????????????????.addAttribute("value",?
- ????????????????????????????????Integer.toString(temp.getCount())) ?
- ????????????????????????.addAttribute( ?
-
????????????????????????????????"color",?
- ????????????????????????????????com.help.Colordef.color[iColor]); ?
- ?
- ????????????????iColor++; ?
- ????????????} ?
- ????????} ?
- ?
-
????????if?(ISCreateFile?==?true)?{ ?
- ????????????XMLWriter?output; ?
-
????????????try?{ ?
-
????????????????output?=?new?XMLWriter(new?FileWriter(new?File(pFileName))); ?
- ????????????????output.write(document); ?
- ?
- ????????????????output.close(); ?
-
????????????}?catch?(IOException?e)?{ ?
-
?????????????????
- ????????????????e.printStackTrace(); ?
- ????????????} ?
- ????????} ?
- ?
-
????????return?document.asXML(); ?
- ????} ?
- ?
-
?????
- ?
- ?
- ?
-
????protected?void?doGet(HttpServletRequest?request,?
-
????????????HttpServletResponse?response)?throws?ServletException,?IOException?{ ?
- ?
-
????????this.doPost(request,?response); ?
-
?????????
- ????} ?
- ?
-
?????
- ?
- ?
- ?
-
????protected?void?doPost(HttpServletRequest?request,?
-
????????????HttpServletResponse?response)?throws?ServletException,?IOException?{ ?
-
?????????
-
????????HttpSession?session?=?request.getSession(false); ?
-
????????TestCase?searchtc?=?(TestCase)?session.getAttribute("searchtc"); ?
- ?
-
????????String?xmldata?=?CreateCasePorjectDibtXmlData(searchtc,?"case?项目用例分布图",?"",?"12",?false,?null); ?
- ????????PrintWriter?out?=?response.getWriter(); ?
-
????????try?{ ?
-
????????????????xmldata?=?xmldata.replaceAll(""","'"); ?
-
????????????????xmldata?=?xmldata.replaceAll("%","%"); ?
- ???????????? ?
-
?????????????????
- ????????????????System.out.println(xmldata); ?
- ????????????????out.write(xmldata); ?
- ?
-
????????}?catch?(NumberFormatException?e)?{ ?
-
????????????out.write("invalid?data"); ?
- ????????} ?
- ????????out.close(); ?
- ????} ?
?
XMLDATA数据如下:
<?xml version='1.0' encoding='UTF-8'?>
< graph caption='case 项目用例分布图' baseFontSize='12' showNames='1' decimalPrecision='0' formatNumberScale='0' yAxisMinValue='0' subCaption=''><set name='bvt:37%' value='77' color='AFD8F8'/><set name='bonline:33%' value='70' color='F6BD0F'/><set name='chatroam:12%' value='25' color='8BBA00'/><set name='imuser_migrate:7%' value='16' color='FF8E46'/><set name='es_refactoring_1:6%' value='13' color='008E8E'/><set name='sms:1%' value='4' color='D64646'/><set name='ww_site_msg:1%' value='3' color='8E468E'/></graph>
js页面端代码
- function?load_project_case_panel()?{ ?
- ????Ext.Ajax.request({ ?
-
????????url?:?'GetCasePorjectDistributedData',?
-
????????success?:?function(response)?{ ?
- ????????????xmlData?=?response.responseText; ?
-
?????????????
-
????????????var?strFlashVars?=?"chartWidth=500&chartHeight=200&debugMode=0&dataXML="+?xmlData+?""; ?
-
????????????var?dis_project_case_panel?=?new?Ext.Panel( ?
- ????????????????????{ ?
- ????????????????????????width?:?Glb.outer_center.getWidth()?*?0.7,?
- ????????????????????????height?:?250,?
-
????????????????????????html?:?'<object?classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'?
-
????????????????????????????????+'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0'?
-
????????????????????????????????+?'width=600?height=250>'?
-
????????????????????????????????+?'<param?name="allowScriptAccess"?value="always"?/>'?
-
????????????????????????????????+?'<param?name="movie"?value="/taiji/static/flash/Pie3D.swf"?/>'?
-
????????????????????????????????+?'<param?name="wmode"?value="transparent"?/>'?
-
????????????????????????????????+?'<param?name="FlashVars"?value='?+?"""+strFlashVars+"""?+'/>'?
-
????????????????????????????????+?'<param?name="quality"?value="high"?/>'?
-
????????????????????????????????+?'<embed?src='#'" /taiji/static/flash/Pie3D.swf"?'?
-
????????????????????????????????+?'FlashVars="'?+strFlashVars?? ?
-
????????????????????????????????+?'"?quality="high"?width=600?height=250?allowScriptAccess="always"?type="application/x-shockwave-flash"'?
-
????????????????????????????????+?'pluginspage="http://www.macromedia.com/go/getflashplayer"?wmode="transparent"/>'?
-
????????????????????????????????+?'</object>'?
- ?
- ????????????????????}); ?
- ????????????dis_project_case_panel.show(); ?
- ????????????outer_center_center.add(dis_project_case_panel); ?
- ????????????Glb.outer_center.show(); ?
- ????????????Glb.outer_center.doLayout(); ?
- ????????},?
-
????????failure?:?function()?{ ?
-
????????????Ext.Msg.alert("提示",?"连接数据库错误或连接超时!"); ?
- ????????} ?
- ????}); ?
- } ?
?