FusionCharts 资料库

FusionCharts的文档结构:

FusionCharts 资料库_第1张图片
 

1.getProductionReportChart.jsp

<%@ page language="java" pageEncoding="gbk"%>
<%@ page import="bussiness.report.*"%>
<%@ include file="/FusionCharts.jsp"%>
<html>
<head></head>
<%
Report report = new Report();

out.println(report.getReportYTDNote());
out.println("</br>");

String pie2dXml = report.getYtdApePieReportXml();
String pie2dHtmlCode = createChartHTML("../fusionCharts/Pie2D.swf", "", pie2dXml
                        , "myFirst4", 900, 600, false) ;
      
out.println(pie2dHtmlCode);

out.println("</br></br>");

%>

 2.Report.java

package bussiness.report;

import business.db.ConnectionPool;

import java.io.PrintStream;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;

public class Report {
	private String itemName;
	private BigDecimal itemValue;
    
	/**
	 * 保留
	 * 
	 * @return
	 */
	public String getReportYTDNote() {
		Calendar now = Calendar.getInstance();

		now.add(5, -1);

		int year = now.get(1);
		int month = now.get(2) + 1;
		int date = now.get(5);

		String dateStr = year + "-" + month + "-" + date;

		StringBuilder sbXml = new StringBuilder();

		sbXml.append("<div style='background: #FFFFE6; margin-left: 0px; width: 640px; border: #FAD185 solid 1px;'>");
		sbXml.append("<p style='Padding: 5px 0px 5px 20px;'>");

		sbXml.append("<table class=tablestyle cellSpacing=0 cellPadding=0 width=560>");
		sbXml.append("<TBODY>");

		sbXml.append("<tr><td align='left'><span class='style9'>YTD:</span><span class='style11'>");
		sbXml.append(dateStr);
		sbXml.append("</span></td></tr></TBODY></table></p></div>");

		return sbXml.toString();
	}

	public static String getYtdApePieReportXml() {
		StringBuilder xmlSb = new StringBuilder();

		Connection conn = null;
		Statement st = null;
		ResultSet rs = null;
		List list = new ArrayList(0);
		try {
			conn = ConnectionPool.getConnection();
			st = conn.createStatement();

			for (rs = st
					.executeQuery("select c.ai_area_desc2, c.ape from (select b.ai_area_desc2,sum(a.Y_NET_DELIVER_APE)/1000 as ape from tu_ods_report_collect_daily a  join vw_ods_area_code2 b on a.branch_code = b.ai_area_code5 where a.load_dt = (select max(load_dt) from tu_ods_report_collect_daily) group by b.ai_area_desc2)c order by ape asc"); rs
					.next();) {
				Report report = new Report();

				report.setItemName(rs.getString(1));
				report.setItemValue(rs.getBigDecimal(2));

				list.add(report);
			}
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		} finally {
			ConnectionPool.releaseStatement(st);
		}

		xmlSb.append("<chart subCaption='(RMB ,000)' baseFontSize='14' caption='Net Delivery APE' startingAngle='90'");

		StringBuilder subCaptionXml = new StringBuilder();
		StringBuilder bodyXml = new StringBuilder();
		BigDecimal total = new BigDecimal(0);
		int i = 0;
		for (Iterator iterator = list.iterator(); iterator.hasNext(); i++) {
			Report report = (Report) iterator.next();

			bodyXml.append("<set label='");
			bodyXml.append(report.getItemName());
			bodyXml.append("' value= '");
			bodyXml.append(report.getItemValue());
			bodyXml.append("' toolText = '");
			bodyXml.append(format3p(report.getItemValue().doubleValue()));
			bodyXml.append("' />");
		}

		xmlSb.append(" palette='4' showPercentValues='1'> ");

		xmlSb.append(bodyXml.toString());

		xmlSb.append("</chart>");

		return xmlSb.toString();
	}


	private static String format3(double value) {
		DecimalFormat decimalFormat = new DecimalFormat("#");
		return decimalFormat.format(value);
	}

	private static String format3p(double value) {
		DecimalFormat decimalFormat = new DecimalFormat(",###");
		return decimalFormat.format(value);
	}

	public String getItemName() {
		return this.itemName;
	}

	public void setItemName(String itemName) {
		this.itemName = itemName;
	}

	public BigDecimal getItemValue() {
		return this.itemValue;
	}

	public void setItemValue(BigDecimal itemValue) {
		this.itemValue = itemValue;
	}

	public static void main(String[] args) {
		System.out.println(format3(654321123456.98987D));
	}
}

 3.发布成功后效果图如下,可以看到flash动画并没有显示:
FusionCharts 资料库_第2张图片
 4.我们Copy上面embed(蓝色部分)的代码到Data.xml,并稍微修改value的值,如下:

<chart subCaption='(RMB ,000)' baseFontSize='14' caption='Net Delivery APE'
	startingAngle='90' palette='4' showPercentValues='1'>
	<set label='上海 Shanghai' value='26' toolText='0' />
	<set label='北京 Beijing' value='56' toolText='0' />
	<set label='天津 Tianjin' value='456' toolText='0' />
	<set label='浙江 Zhejiang' value='233' toolText='0' />
	<set label='广东 Guangdong' value='111' toolText='0' />
	<set label='江苏 Jiangsu' value='25' toolText='0' />
	<set label='河北 Hebei' value='45' toolText='0' />
	<set label='山东 Shandong' value='78' toolText='0' />
</chart>

5.编写一个测试JSP(index.jsp)

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
      <title>My First FusionCharts</title>
   </head>
   <body bgcolor="#ffffff">
      <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="900" height="300" id="Column3D" >
         <param name="movie" value="fusionCharts/Pie2D.swf" />
         <param name="FlashVars" value="&dataURL=data/Data.xml">
         <param name="quality" value="high" />
         <embed src="fusionCharts/Pie2D.swf" flashVars="&dataURL= data/Data.xml" quality="high" width="900" height="300" name="Column3D" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
      </object>
</body>
</html>

 最终项目的目录结构如下:

FusionCharts 资料库_第3张图片
 6.发布成功后访问index.jsp页面,效果如下:

FusionCharts 资料库_第4张图片

说明:没数据会造成flash动画不能显示

 参考:http://blog.csdn.net/chenssy/article/details/9773797

你可能感兴趣的:(FusionCharts)