效果漂亮且支持多达40多种报表
看图:
简单说下这个东东在jsp环境下应用.
java代码:
package com.eline.epicc.utils;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/** *//**
* 报表生成公共类(创建FusionCharts<flash cool>)
*
* @author zdw
*
*/
public ChartUtils
{
/** *//**
* 对Url数据转码思路方法
* @param strDataURL - chart数据url
* @param addNoCacheStr - 非缓存Cache串
* @
*/
public String encodeDataURL(String strDataURL, String addNoCacheStr,
HttpServletResponse response)
{
String encodedURL = strDataURL;
(addNoCacheStr.equals("true"))
{
java.util.Calendar nowCal = java.util.Calendar.getInstance;
java.util.Date now = nowCal.getTime;
java.text.SimpleDateFormat sdf = java.text.SimpleDateFormat(
"MM/dd/yyyy HH_mm_ss a");
String strNow = sdf.format(now);
(strDataURL.indexOf("?") > 0)
{
encodedURL = strDataURL + "&FCCurrTime=" + strNow;
}
{
strDataURL = strDataURL + "?FCCurrTime=" + strNow;
}
encodedURL = response.encodeURL(strDataURL);
}
encodedURL;
}
/** *//**
* 用HTML+JavaScript创建FusionCharts对象(用此方式需要导入FusionCharts.js文件)
* @param chartSWF -
* flash文件位置即chart图表类型
* @param strURL - xml数据源
* @param strXML - 流
* @param chartId - chart对象在HTML中唯标识
* @param chartWidth - flash chart 宽度(单位px)
* @param chartHeight - flash chart 高度(单位px)
* @param debugMode - 是否开启chart 调试模式
* @param registerWithJS - 是否注册自己
*/
public String createChart(String chartSWF, String strURL,
String strXML, String chartId, chartWidth, chartHeight,
boolean debugMode, boolean registerWithJS)
{
StringBuffer strBuf = StringBuffer;
strBuf.append("<!--START Script Block for Chart -->n");
strBuf.append("tt<div id='" + chartId + "Div' align='center'>n");
strBuf.append("ttttChart.n");
strBuf.append("tt</div>n");
strBuf.append("tt<script type='text/javascript'>n");
Boolean registerWithJSBool = Boolean(registerWithJS);
Boolean debugModeBool = Boolean(debugMode);
regWithJSInt = boolToNum(registerWithJSBool);
debugModeInt = boolToNum(debugModeBool);
strBuf.append("ttttvar chart_" + chartId + " = FusionCharts('"
+ chartSWF + "', '" + chartId + "', '" + chartWidth + "', '"
+ chartHeight + "', '" + debugModeInt + "', '" + regWithJSInt
+ "');n");
(strXML.equals(""))
{
strBuf.append("tttt//Set the dataURL of the chartn");
strBuf.append("ttttchart_" + chartId + ".DataURL(""
+ strURL + "");n");
}
{
strBuf
.append("tttt//Provide entire XML data using dataXML methodn");
strBuf.append("ttttchart_" + chartId + ".DataXML(""
+ strXML + "");n");
}
strBuf.append("tttt//Finally, render the chart.n");
strBuf.append("ttttchart_" + chartId + ".render("" + chartId
+ "Div");n");
strBuf.append("tt</script>n");
strBuf.append("tt<!--END Script Block for Chart-->n");
strBuf.sub(0);
}
/** *//**
* 创建swf charts对象(HTML)
*
* @param chartSWF -
* flash文件位置即chart图表类型
*
* @param strURL -
* xml数据源
* @param strXML -
* If you end to use dataXML method for this chart, pass the
* XML data as this parameter. Else, it to "" (in of
* dataURL method)
* @param chartId -
* chart对象在HTML中唯标识
* @param chartWidth -
* flash chart 宽度(单位px)
* @param chartHeight -
* flash chart 高度(单位px)
* @param debugMode -
* 是否开启chart 调试模式
*/
public String createChartHTML(String chartSWF, String strURL,
String strXML, String chartId, chartWidth, chartHeight,
boolean debugMode)
{
String strFlashVars = "";
Boolean debugModeBool = Boolean(debugMode);
(strXML.equals(""))
{
strFlashVars = "chartWidth=" + chartWidth + "&chartHeight="
+ chartHeight + "&debugMode=" + boolToNum(debugModeBool)
+ "&dataURL=" + strURL + "";
}
{
strFlashVars = "chartWidth=" + chartWidth + "&chartHeight="
+ chartHeight + "&debugMode=" + boolToNum(debugModeBool)
+ "&dataXML=" + strXML + "";
}
StringBuffer strBuf = StringBuffer;
// 开始输出Object chart
strBuf.append("tt<!--START Code Block for Chart-->n");
strBuf
.append("tttt<object id='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"
+ chartWidth
+ "' height='"
+ chartHeight
+ "' id='"
+ chartId + "'>n");
strBuf
.append("tttt <param name='allowScriptAccess' value='always' />n");
strBuf.append("tttt <param name='movie' value='" + chartSWF
+ "'/>n");
strBuf.append("tttt<param name='FlashVars' value="" + strFlashVars
+ "" />n");
strBuf.append("tttt <param name='quality' value='high' />n");
strBuf
.append("tttt<embed src='"
+ chartSWF
+ "' FlashVars=""
+ strFlashVars
+ "" quality='high' width='"
+ chartWidth
+ "' height='"
+ chartHeight
+ "' name='"
+ chartId
+ "' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />n");
strBuf.append("tt</object>n");
strBuf.append("tt<!--END Code Block for Chart-->n");
strBuf.sub(0);
}
/** *//**
* 提供快速输出Chart便捷思路方法(基于流方式)
*
* @param chartSWF :
* flash文件位置即chart图表类型
* @param strXml :
* xml文件流(格式)
* @param chartId :
* chart对象在HTML中唯标识
* @param chartWidth :
* flash chart 宽度(单位px)
* @param chartHeight:
* flash chart 高度(单位px)
* @param response :
* reponse对象
*/
public void outChartHTML(String chartSWF, String strXml,
String chartId, chartWidth, chartHeight,
HttpServletResponse response)
{
String str = createChartHTML(chartSWF, "", strXml, chartId, chartWidth,
chartHeight, false);
try
{
response.getWriter.write(str);
} catch (IOException e)
{
e.prStackTrace;
}
}
/** *//**
* 提供快速输出Chart便捷思路方法(基于xml文件方式)
*
* @param chartSWF :
* flash文件位置即chart图表类型
* @param strURL :
* xml数据源(路径格式)
* @param chartId :
* chart对象在HTML中唯标识
* @param chartWidth :
* flash chart 宽度(单位px)
* @param chartHeight:
* flash chart 高度(单位px)
* @param response :
* reponse对象
*/
public void outChartSourceHTML(String chartSWF, String strURL,
String chartId, chartWidth, chartHeight,
HttpServletResponse response)
{
String str = createChartHTML(chartSWF, strURL, "", chartId, chartWidth,
chartHeight, false);
try
{
response.getWriter.write(str);
} catch (IOException e)
{
e.prStackTrace;
}
}
/** *//**
* bollean转换为
*/
private boolToNum(Boolean bool)
{
num = 0;
(bool.booleanValue)
{
num = 1;
}
num;
}
}
jsp:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.eline.epicc.utils.ChartUtils"%>
<%@page import="com.eline.epicc.utils.Constants"%>
<HTML>
<HEAD>
<TITLE>FusionCharts - Simple Column 3D Chart</TITLE>
</HEAD>
<BODY>
<%
//文件源举例
ChartUtils.outChartSourceHTML("common/charts/Column3D.swf",
"data.xml", "myFirst", 600, 300, response);
String arrData = String[6][2];
//产品名字
arrData[0][0] = "Product A";
arrData[1][0] = "Product B";
arrData[2][0] = "Product C";
arrData[3][0] = "Product D";
arrData[4][0] = "Product E";
arrData[5][0] = "Product F";
arrData[0][1] = "567500";
arrData[1][1] = "815300";
arrData[2][1] = "556800";
arrData[3][1] = "734500";
arrData[4][1] = "676800";
arrData[5][1] = "648500";
//Now, we need to convert this data o XML. We convert using concatenation.
String strXML;
i = 0;
strXML = "<chart caption='Sales by Product' numberPrefix='$' formatNumberScale='0'>";
for (i = 0; i < arrData.length; i)
{
strXML = strXML + "< label='" + arrData[i][0]
+ "' value='" + arrData[i][1] + "' />";
}
strXML = strXML + "</chart>";
//String串流举例
ChartUtils.outChartHTML(Constants.COLUMN3D, strXML,
"myFirst", 600, 300, response);
%>
</BODY>
</HTML>
xml数据文件:
<?xml version="1.0" encoding="UTF-8"?>
<chart caption='Monthly Unit Sales' xAxisName='Month' yAxisName='Units' showValues='0' formatNumberScale='0' showBorder='1'>
< label='Jan' value='462' />
< label='Feb' value='857' />
< label='Mar' value='671' />
< label='Apr' value='494' />
< label='May' value='761' />
< label='Jun' value='960' />
< label='Jul' value='629' />
< label='Aug' value='622' />
< label='Sep' value='376' />
< label='Oct' value='494' />
< label='Nov' value='761' />
< label='Dec' value='960' />
</chart>
当然FusionCharts支持很多种编程语言具体你可以看附件CHM.
附上破解版下载和我做Chm帮助文档
FusionChartsV3下载地址:
http://flashview.ddvip.com/2009_01/FusionChartsV3完美破解版(附Chm帮助文档).rar
最新评论