extjs 之panel嵌入flash饼状图

java端获取数据代码


/**
	 * 创建产品线接口数量统计数据的XML格式数据
	 * 
	 * @param caption
	 *            报表标题
	 * @param xAxisName
	 *            横轴名称
	 * @param yAxisName
	 *            纵轴名称
	 * @param baseFontSize
	 *            字体大小 以12为佳
	 * @param ISCreateFile
	 *            是否要创建为XML文件,TRUE表示要创建文件
	 * @param pFileName
	 *            XML文件的输出路径与文件名称
	 * @return String XML格式字符串,用于图表显示
	 */
	public String CreateCasePorjectDibtXmlData(TestCase searchtc,String caption, String subCaption,
			String baseFontSize, boolean ISCreateFile, String pFileName) {
    	
    	
		//List<StatisticsOfIfaceNumber> IFaceNumberList = StatisticsOfIfaceNumberDao
			//	.getStatisticsOfIfaceNumberList();
		//int ListSize = IFaceNumberList.size();
    	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) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return document.asXML();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		this.doPost(request, response);
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		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("%","%");
			
				//xmldata = URLEncoder.encode(xmldata,"utf-8");
				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;
				//alert(xmlData);
				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,0,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("提示", "连接数据库错误或连接超时!");
			}
		});
	}


页面效果








  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值