|
项目中需要用到报表,发现这个flash做的工具很好用~
效果漂亮,且支持多达40多种报表。
看图:
简单说下这个东东在jsp环境下的应用.
java代码:
package com.eline.epicc.utils;
import java.io.ioexception;
import javax.servlet.http.httpservletresponse;
/** *//**
* 报表生成公共类(创建fusioncharts)
*
* @author zdw
*
*/
public class chartutils
{
/** *//**
* 对url数据转码的方法
* @param strdataurl - chart的数据url
* @param addnocachestr - 非缓存字符串
* @return
*/
public string encodedata
{
string encodedurl = strdataurl;
if (addnocachestr.equals("true"))
{
java.util.calendar nowcal = java.util.calendar.getinstance();
java.util.date now = nowcal.gettime();
java.text.simpledateformat sdf = new java.text.simpledateformat(
"mm/dd/yyyy hh_mm_ss a");
string strnow = sdf.format(now);
if (strdataurl.indexof("?") > 0)
{
encodedurl = strdataurl "&fccurrtime=" strnow;
}
else
{
strdataurl = strdataurl "?fccurrtime=" strnow;
}
encodedurl = response.encode;
}
return 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 static string createchart(string chartswf, string strurl,
string strxml, string chartid, int chartwidth, int chartheight,
boolean debugmode, boolean registerwithjs)
{
stringbuffer strbuf = new stringbuffer();
strbuf.append("\n");
strbuf.append("\t\t" chartid "div' align='center'>\n");
strbuf.append("\t\t\t\tchart.\n");
strbuf.append("\t\t \n ");
strbuf.append("\t\t");
boolean registerwithjsbool = new boolean(registerwithjs);
boolean debugmodebool = new boolean(debugmode);
int regwithjsint = booltonum(registerwithjsbool);
int debugmodeint = booltonum(debugmodebool);
strbuf.append("\t\t\t\tvar chart_" chartid " = new fusioncharts('"
chartswf "', '" chartid "', '" chartwidth "', '"
chartheight "', '" debugmodeint "', '" regwithjsint
"');\n");
if (strxml.equals(""))
{
strbuf.append("\t\t\t\t//set the dataurl of the chart\n");
strbuf.append("\t\t\t\tchart_" chartid ".setdata;\n");
}
else
{
strbuf
.append("\t\t\t\t//provide entire xml data using dataxml method\n");
strbuf.append("\t\t\t\tchart_" chartid ".setdataxml(\""
strxml "\");\n");
}
strbuf.append("\t\t\t\t//finally, render the chart.\n");
strbuf.append("\t\t\t\tchart_" chartid ".render(\"" chartid
"div\");\n");
strbuf.append("\t\t\n");
strbuf.append("\t\t\n");
return strbuf.substring(0);
}
/** *//**
* 创建swf charts对象(html)
*
* @param chartswf -
* flash文件的位置,即chart图表类型
*
* @param strurl -
* xml数据源
* @param strxml -
* if you intend to use dataxml method for this chart, pass the
* xml data as this parameter. else, set it to "" (in case of
* dataurl method)
* @param chartid -
* chart对象在html中的唯一标识
* @param chartwidth -
* flash chart 的宽度(单位px)
* @param chartheight -
* flash chart 的高度(单位px)
* @param debugmode -
* 是否开启chart 调试模式
*/
public static string createcharthtml(string chartswf, string strurl,
string strxml, string chartid, int chartwidth, int chartheight,
boolean debugmode)
{
string strflashvars = "";
boolean debugmodebool = new boolean(debugmode);
if (strxml.equals(""))
{
strflashvars = "chartwidth=" chartwidth "&chartheight="
chartheight "&debugmode=" booltonum(debugmodebool)
"&dataurl=" strurl "";
}
else
{
strflashvars = "chartwidth=" chartwidth "&chartheight="
chartheight "&debugmode=" booltonum(debugmodebool)
"&dataxml=" strxml "";
}
stringbuffer strbuf = new stringbuffer();
// 开始输出object chart
strbuf.append("\t\t\n");
strbuf
.append("\t\t\t\t
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 charttitle>
head>
<body>
<%
//文件源示例
chartutils.outchartsourcehtml("common/charts/column3d.swf",
"data.xml", "myfirst", 600, 300, response);
string[][] arrdata = new 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 into xml. we convert using string concatenation.
string strxml;
int i = 0;
strxml = "";
for (i = 0; i < arrdata.length; i)
{
strxml = strxml "" arrdata[i][0]
"' value='" arrdata[i][1] "' />";
}
strxml = strxml "";
//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'>
='jan' value='462' />
<set label='feb' value='857' />
<set label='mar' value='671' />
<set label='apr' value='494' />
<set label='may' value='761' />
<set label='jun' value='960' />
<set label='jul' value='629' />
<set label='aug' value='622' />
<set label='sep' value='376' />
<set label='oct' value='494' />
<set label='nov' value='761' />
<set label='dec' value='960' />
chart>
当然fusioncharts支持很多种编程语言,具体你可以看附件的chm.
附上破解版的下载和我做的chm帮助文档。
|