extjs 之panel嵌入flash饼状图

简介:

java端获取数据代码

 

 
  1. /**  
  2.      * 创建产品线接口数量统计数据的XML格式数据  
  3.      *   
  4.      * @param caption  
  5.      *            报表标题  
  6.      * @param xAxisName  
  7.      *            横轴名称  
  8.      * @param yAxisName  
  9.      *            纵轴名称  
  10.      * @param baseFontSize  
  11.      *            字体大小 以12为佳  
  12.      * @param ISCreateFile  
  13.      *            是否要创建为XML文件,TRUE表示要创建文件  
  14.      * @param pFileName  
  15.      *            XML文件的输出路径与文件名称  
  16.      * @return String XML格式字符串,用于图表显示  
  17.      */ 
  18.     public String CreateCasePorjectDibtXmlData(TestCase searchtc,String caption, String subCaption,  
  19.             String baseFontSize, boolean ISCreateFile, String pFileName) {  
  20.           
  21.           
  22.         //List<StatisticsOfIfaceNumber> IFaceNumberList = StatisticsOfIfaceNumberDao  
  23.             //  .getStatisticsOfIfaceNumberList();  
  24.         //int ListSize = IFaceNumberList.size();  
  25.         CaseReportService cs = new CaseReportService();  
  26.           
  27.         List<DisCaseProject> ldcp = cs.getDisCaseProjectData(searchtc);  
  28.         int ListSize = ldcp.size();  
  29.         Document document = DocumentHelper.createDocument();  
  30.         Element root = document.addElement("graph").addAttribute("caption",  
  31.                 caption).addAttribute("baseFontSize", baseFontSize)  
  32.                 .addAttribute("showNames""1").addAttribute(  
  33.                         "decimalPrecision""0").addAttribute(  
  34.                         "formatNumberScale""0").addAttribute("yAxisMinValue",  
  35.                         "0");  
  36.         if (subCaption != null) {  
  37.             root.addAttribute("subCaption", subCaption);  
  38.         }  
  39.         int totalCaseCount = 0;  
  40.           
  41.         Iterator<DisCaseProject> its = ldcp.iterator();  
  42.         while (its.hasNext()) {  
  43.             DisCaseProject Temp_CaseCount = its.next();  
  44.             if (Temp_CaseCount == null)  
  45.                 break;  
  46.             totalCaseCount = totalCaseCount + Temp_CaseCount.getCount();  
  47.         }  
  48.           
  49.         if (ListSize > com.help.Colordef.colorCount) {  
  50.             String color[] = new String[ListSize];  
  51.             for (int i = 0; i < ListSize; i++) {  
  52.                 double n = Math.random();  
  53.                 double m = Math.random();  
  54.                 double k = Math.random();  
  55.                 int j = (int) (n * m * k * 0xFFFFFF);  
  56.                 color[i] = Integer.toHexString(j);  
  57.             }  
  58.             Iterator<DisCaseProject> it = ldcp.iterator();  
  59.  
  60.             int iColor = 0;  
  61.             while (it.hasNext()) {  
  62.                 DisCaseProject temp = it.next();  
  63.                 if (temp == null)  
  64.                     break;  
  65.                 root.addElement("set").addAttribute(  
  66.                                 "name",  
  67.                                 temp.getProjectname()  
  68.                                         + ":" 
  69.                                         + (int) (((float) temp.getCount()/(float)totalCaseCount) * 100)  
  70.                                         + "%").addAttribute("value",  
  71.                                 Integer.toString(temp.getCount()))  
  72.                         .addAttribute("color", color[iColor]);  
  73.                 iColor++;  
  74.             }  
  75.         } else {  
  76.             Iterator<DisCaseProject> it = ldcp.iterator();  
  77.  
  78.             int iColor = 0;  
  79.             while (it.hasNext()) {  
  80.                 DisCaseProject temp = it.next();  
  81.                 if (temp == null)  
  82.                     break;  
  83.  
  84.                 root  
  85.                         .addElement("set")  
  86.                         .addAttribute(  
  87.                                 "name",  
  88.                                 temp.getProjectname()  
  89.                                         + ":" 
  90.                                         + (int) (((float) temp.getCount()/ (float) totalCaseCount) * 100)  
  91.                                         + "%")  
  92.                         .addAttribute("value",  
  93.                                 Integer.toString(temp.getCount()))  
  94.                         .addAttribute(  
  95.                                 "color",  
  96.                                 com.help.Colordef.color[iColor]);  
  97.  
  98.                 iColor++;  
  99.             }  
  100.         }  
  101.  
  102.         if (ISCreateFile == true) {  
  103.             XMLWriter output;  
  104.             try {  
  105.                 output = new XMLWriter(new FileWriter(new File(pFileName)));  
  106.                 output.write(document);  
  107.  
  108.                 output.close();  
  109.             } catch (IOException e) {  
  110.                 // TODO Auto-generated catch block  
  111.                 e.printStackTrace();  
  112.             }  
  113.         }  
  114.  
  115.         return document.asXML();  
  116.     }  
  117.  
  118.     /**  
  119.      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse  
  120.      *      response)  
  121.      */ 
  122.     protected void doGet(HttpServletRequest request,  
  123.             HttpServletResponse response) throws ServletException, IOException {  
  124.  
  125.         this.doPost(request, response);  
  126.         // TODO Auto-generated method stub  
  127.     }  
  128.  
  129.     /**  
  130.      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse  
  131.      *      response)  
  132.      */ 
  133.     protected void doPost(HttpServletRequest request,  
  134.             HttpServletResponse response) throws ServletException, IOException {  
  135.         // TODO Auto-generated method stub  
  136.         HttpSession session = request.getSession(false);  
  137.         TestCase searchtc = (TestCase) session.getAttribute("searchtc");  
  138.  
  139.         String xmldata = CreateCasePorjectDibtXmlData(searchtc, "case 项目用例分布图""""12"falsenull);  
  140.         PrintWriter out = response.getWriter();  
  141.         try {  
  142.                 xmldata = xmldata.replaceAll("\"","'");  
  143.                 xmldata = xmldata.replaceAll("%","%");  
  144.               
  145.                 //xmldata = URLEncoder.encode(xmldata,"utf-8");  
  146.                 System.out.println(xmldata);  
  147.                 out.write(xmldata);  
  148.  
  149.         } catch (NumberFormatException e) {  
  150.             out.write("invalid data");  
  151.         }  
  152.         out.close();  
  153.     }  

 

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页面端代码

 
  1. function load_project_case_panel() {  
  2.     Ext.Ajax.request({  
  3.         url : 'GetCasePorjectDistributedData',  
  4.         success : function(response) {  
  5.             xmlData = response.responseText;  
  6.             //alert(xmlData);  
  7.             var strFlashVars = "chartWidth=500&chartHeight=200&debugMode=0&dataXML="+ xmlData+ "";  
  8.             var dis_project_case_panel = new Ext.Panel(  
  9.                     {  
  10.                         width : Glb.outer_center.getWidth() * 0.7,  
  11.                         height : 250,  
  12.                         html : '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' 
  13.                                 +'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' 
  14.                                 + 'width=600 height=250>' 
  15.                                 + '<param name="allowScriptAccess" value="always" />' 
  16.                                 + '<param name="movie" value="/taiji/static/flash/Pie3D.swf" />' 
  17.                                 + '<param name="wmode" value="transparent" />' 
  18.                                 + '<param name="FlashVars" value=' + "\""+strFlashVars+"\"" +'/>' 
  19.                                 + '<param name="quality" value="high" />' 
  20.                                 + '<embed src="/taiji/static/flash/Pie3D.swf" ' 
  21.                                 + 'FlashVars=\"' +strFlashVars    
  22.                                 + '\" quality="high" width=600 height=250 allowScriptAccess="always" type="application/x-shockwave-flash"' 
  23.                                 + 'pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent"/>' 
  24.                                 + '</object>' 
  25.  
  26.                     });  
  27.             dis_project_case_panel.show();  
  28.             outer_center_center.add(dis_project_case_panel);  
  29.             Glb.outer_center.show();  
  30.             Glb.outer_center.doLayout();  
  31.         },  
  32.         failure : function() {  
  33.             Ext.Msg.alert("提示""连接数据库错误或连接超时!");  
  34.         }  
  35.     });  
  36. }  

 

 


本文转自elbertchen 51CTO博客,原文链接:http://blog.51cto.com/linkyou/751969,如需转载请自行联系原作者

相关文章
|
前端开发 JavaScript
酷炫一款动态背景+鼠标点击效果(HTML +js canvas)
前言 之前用于装饰个人的Hexo博客背景和点击事件,于是动手弄弄顺便学习学习,现在分享出来给有需要的人。 废话不多说 ,分享一款酷炫的页面动态背景 效果见( https://fivecc.cn )
258 1
酷炫一款动态背景+鼠标点击效果(HTML +js canvas)
|
移动开发 HTML5 定位技术
openlayers通过overlay html5 css3设置图标闪烁效果
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gisdoer/article/details/79730873 openlayers通过overlay html5 css3设置图标闪烁效果 http://www.
2098 0
|
JavaScript 前端开发 数据格式
ExtJS 6 gridPanel绘制表格并填充数据的例子
Ext.grid.Panel 是表格,可以显示数据,我们来看看它的基本用法:View + Store + Model使用上述三个“部分”就可以完整的,最简易的在Ext的世界中绘制一个用于显示数据库中数据的UI View部分的代码 Ext.
3026 0
|
前端开发 JavaScript
|
移动开发 前端开发 JavaScript
网页,html5,canvas,js 动态绘制柱形图
&lt;!DOCTYPE html&gt;     &lt;head&gt;&lt;title&gt;chart demo&lt;/title&gt;         &lt;style&gt;             #chartContainer{                 border:solid 1px #999;                       
1623 0