工程的目录结构以及所需的文件如下:
成功发布成功后的效果图如下:(拼接的XML中value必须有值,否则flash可能无法正常显示)
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 msColum2dXml2 = report.getYtdApeMsLine2DXml2(); String msColum2dHtmlCode2 = createChartHTML("../fusionCharts/MSLine.swf", "", msColum2dXml2 , "myFirst7", 1000, 600, false) ; out.println(msColum2dHtmlCode2); out.println("</br></br>"); %>
2.数据源来源于Oracle数据库,因此需要编写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 { /** * 保留 * @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(); } /** * 保留 * @return */ public static String getYtdApeMsLine2DXml2() { List categoryLst = new ArrayList(); List budgetLst = new ArrayList(); List netDeliverLst = new ArrayList(); Connection conn = null; Statement st = null; ResultSet rs = null; try { conn = ConnectionPool.getConnection(); st = conn.createStatement(); for (rs = st .executeQuery("SELECT SUBSTR(LOAD_DT,1,6),SUM(Y_NET_DELIVER_APE)/1000 as NET_DELIVER_CASH,SUM(Y_BUDGET_APE)/1000 as BUDGET_CASH FROM tu_ods_report_collect_daily WHERE LOAD_DT IN (SELECT MAX(LOAD_DT) FROM TU_ODS_REPORT_COLLECT_DAILY WHERE LOAD_DT <TO_CHAR(TRUNC(SYSDATE,'MM'),'YYYYMMDD') GROUP BY SUBSTR(LOAD_DT,1,6)) GROUP BY SUBSTR(LOAD_DT,1,6)"); rs .next();) { categoryLst.add(rs.getString(1)); budgetLst.add(format3(rs.getDouble(3))); netDeliverLst.add(format3(rs.getDouble(2))); } } catch (SQLException sqle) { sqle.printStackTrace(); } finally { ConnectionPool.releaseStatement(st); ConnectionPool.releaseConnection(conn); } StringBuilder xmlSb = new StringBuilder(); xmlSb.append("<chart baseFontSize='14' caption='YTD Budget APE And Net Delivery APE Month' subCaption='(RMB ,000)'"); xmlSb.append("lineThickness='1' showValues='0' formatNumberScale='0' "); xmlSb.append("anchorRadius='2' divLineAlpha='20' divLineColor='CC3300' "); xmlSb.append("divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' "); xmlSb.append("alternateHGridColor='CC3300' shadowAlpha='40' labelStep='1' numvdivlines='5' "); xmlSb.append("chartRightMargin='35' bgColor='FFFFFF,CC3300' "); xmlSb.append("bgAngle='270' bgAlpha='10,10'>"); if (categoryLst.size() > 0) { xmlSb.append("<categories>"); } for (Iterator iterator = categoryLst.iterator(); iterator.hasNext();) { String category = (String) iterator.next(); xmlSb.append("<category label='"); xmlSb.append(category); xmlSb.append("' />"); } if (categoryLst.size() > 0) { xmlSb.append("</categories>"); } if (budgetLst.size() > 0) { xmlSb.append("<dataset seriesName='BUDGET APE' anchorBorderColor='1D8BD1' anchorBgColor='1D8BD1'>"); } for (Iterator iterator = budgetLst.iterator(); iterator.hasNext();) { String budget = (String) iterator.next(); xmlSb.append("<set value='"); xmlSb.append(budget); xmlSb.append("' />"); } if (budgetLst.size() > 0) { xmlSb.append("</dataset>"); } if (netDeliverLst.size() > 0) { xmlSb.append("<dataset seriesName='NET DELIVERY APE' anchorBorderColor='F1683C' anchorBgColor='F1683C'>"); } for (Iterator iterator = netDeliverLst.iterator(); iterator.hasNext();) { String actual = (String) iterator.next(); xmlSb.append("<set value='"); xmlSb.append(actual); xmlSb.append("' />"); } if (budgetLst.size() > 0) { xmlSb.append("</dataset>"); } xmlSb.append("</chart>"); return xmlSb.toString(); } private static String format3(double value) { DecimalFormat decimalFormat = new DecimalFormat("#"); return decimalFormat.format(value); } }
3.ConnectionPool.java只是一个数据库连接类,没别特别之处,因此在这就不写了。
4.FusionCharts.jsp文件如下:
<%!//Page: FusionCharts.jsp //Author: InfoSoft Global (P) Ltd. //This page contains functions that can be used to create FusionCharts. /** * Encodes the dataURL before it's served to FusionCharts. * If you have parameters in your dataURL, you necessarily need to encode it. * @param strDataURL - dataURL to be fed to chart * @param addNoCacheStr - Whether to add aditional string to URL to disable caching of data * @return */ public String encodeDataURL(String strDataURL, String addNoCacheStr, HttpServletResponse response) { String encodedURL = strDataURL; //Add the no-cache string if required if (addNoCacheStr.equals("true")) { /*We add ?FCCurrTime=xxyyzz If the dataURL already contains a ?, we add &FCCurrTime=xxyyzz We send the date separated with '_', instead of the usual ':' as FusionCharts cannot handle : in URLs */ 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.encodeURL(strDataURL); } return encodedURL; } /** * Creates the Chart HTML+Javascript to create the FusionCharts object with the given parameters. * This method uses JavaScript to overcome the IE browser problem with SWF wherein you have to 'Click to activate' the control * @param chartSWF - SWF File Name (and Path) of the chart which you intend to plot * @param strURL - If you intend to use dataURL method for this chart, pass the URL as this parameter. Else, set it to "" (in case of dataXML method) * @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 - Id for the chart, using which it will be recognized in the HTML page. Each chart on the page needs to have a unique Id. * @param chartWidth - Intended width for the chart (in pixels) * @param chartHeight - Intended height for the chart (in pixels) * @param debugMode - Whether to start the chart in debug mode * @param registerWithJS - Whether to ask chart to register itself with JavaScript */ public String createChart(String chartSWF, String strURL, String strXML, String chartId, int chartWidth, int chartHeight, boolean debugMode, boolean registerWithJS) { StringBuffer strBuf = new StringBuffer(); /* First we create a new DIV for each chart. We specify the name of DIV as "chartId"Div. DIV names are case-sensitive. */ strBuf.append("<!--START Script Block for Chart -->\n"); strBuf.append("\t\t<div id='" + chartId + "Div' align='center'>\n"); strBuf.append("\t\t\t\tChart.\n"); /*The above text "Chart" is shown to users before the chart has started loading (if there is a lag in relaying SWF from server). This text is also shown to users who do not have Flash Player installed. You can configure it as per your needs.*/ strBuf.append("\t\t</div>\n"); /*Now, we render the chart using FusionCharts Class. Each chart's instance (JavaScript) Id is named as chart_"chartId".*/ strBuf.append("\t\t<script type='text/javascript'>\n"); //Instantiate the Chart 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"); //Check whether we've to provide data using dataXML method or dataURL method if (strXML.equals("")) { strBuf.append("\t\t\t\t//Set the dataURL of the chart\n"); strBuf.append("\t\t\t\tchart_" + chartId + ".setDataURL(\"" + strURL + "\");\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</script>\n"); strBuf.append("\t\t<!--END Script Block for Chart-->\n"); return strBuf.substring(0); } /** * Creates the Chart HTML to embed the swf object with the given parameters * @param chartSWF - SWF File Name (and Path) of the chart which you intend to plot * @param strURL - If you intend to use dataURL method for this chart, pass the URL as this parameter. Else, set it to "" (in case of dataXML method) * @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 - Id for the chart, using which it will be recognized in the HTML page. Each chart on the page needs to have a unique Id. * @param chartWidth - Intended width for the chart (in pixels) * @param chartHeight - Intended height for the chart (in pixels) * @param debugMode - Whether to start the chart in debug mode */ public String createChartHTML(String chartSWF, String strURL, String strXML, String chartId, int chartWidth, int chartHeight, boolean debugMode) { /*Generate the FlashVars string based on whether dataURL has been provided or dataXML.*/ String strFlashVars = ""; Boolean debugModeBool = new Boolean(debugMode); if (strXML.equals("")) { //DataURL Mode strFlashVars = "chartWidth=" + chartWidth + "&chartHeight=" + chartHeight + "&debugMode=" + boolToNum(debugModeBool) + "&dataURL=" + strURL + ""; } else { //DataXML Mode strFlashVars = "chartWidth=" + chartWidth + "&chartHeight=" + chartHeight + "&debugMode=" + boolToNum(debugModeBool) + "&dataXML=" + strXML + ""; } StringBuffer strBuf = new StringBuffer(); // START Code Block for Chart strBuf.append("\t\t<!--START Code Block for Chart-->\n"); strBuf.append("\t\t\t\t<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='" + chartWidth + "' height='" + chartHeight + "' id='" + chartId + "'>\n"); strBuf.append("\t\t\t\t <param name='allowScriptAccess' value='always' />\n"); strBuf.append("\t\t\t\t <param name='movie' value='" + chartSWF + "'/>\n"); strBuf.append("\t\t\t\t<param name='FlashVars' value=\"" + strFlashVars + "\" />\n"); strBuf.append("\t\t\t\t <param name='quality' value='high' />\n"); strBuf.append("\t\t\t\t<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("\t\t</object>\n"); // END Code Block for Chart strBuf.append("\t\t<!--END Code Block for Chart-->\n"); return strBuf.substring(0); } /** * Converts boolean to corresponding integer * @param bool - The boolean that is to be converted to number * @return int - 0 or 1 representing the given boolean value */ public int boolToNum(Boolean bool) { int num = 0; if (bool.booleanValue()) { num = 1; } return num; }%>
注意:使用google浏览器查看页面元素
相关推荐
本项目主要关注的是如何在Java后端与FusionCharts结合,通过JavaBean实体类、Action类以及JSP页面来实现图表数据的处理和展示。 首先,`FusionCharts_java后台`指的是利用Java技术搭建后端服务,以支持FusionCharts...
二是通过WebView的`addJavascriptInterface()`方法创建一个Java对象,使其可在JavaScript环境中调用,从而传递Android应用中的数据。 5. **事件处理**: - FusionCharts支持交互式图表,用户与图表交互时会产生...
本文将深入探讨如何使用Java实现FusionCharts图表的导出功能,包括导出为图片和PDF文件。 首先,要实现这个功能,你需要在项目中引入FusionCharts的Java库。FusionCharts提供了Java SDK,通过它我们可以与...
本文将详细讲解如何在Eclipse这个Java集成开发环境中制作FusionCharts的例子,包括柱状图和饼图。 首先,我们需要了解FusionCharts的基础。FusionCharts是一个基于Web的图表组件,它支持超过90种不同类型的图表,如...
4. **JSP**:在Java环境中,JSP开发者可以通过FusionCharts的Java类库,结合Servlet或JSP页面来生成图表数据。 **三、图表类型及特性** 1. **多样化图表**:FusionCharts支持20+种不同类型的图表,满足各种数据分析...
【FusionCharts柱状图_jsp】是一个关于在Java服务器页面(JSP)中使用FusionCharts库创建柱状图表的实例源代码。FusionCharts是一款强大的JavaScript图表库,能够帮助开发者生成交互式、视觉吸引人的图表。在这个...
在本压缩包中,包含了官方的FusionCharts Suite XT软件包以及一些示例文件,方便我们了解和学习如何使用FusionCharts。 `fusioncharts-suite-xt.zip`是FusionCharts的核心组件,包含了所有必要的JavaScript库、CSS...
- 通过纯JavaScript或与服务器端语言(如PHP、ASP.NET、Java等)集成,可以轻松地在网页中嵌入图表。 2. **FusionCharts API基础** - FusionCharts的初始化:首先需要创建一个`<div>`元素作为图表容器,然后通过...
在这个例子中,我们创建了一个名为`myChart`的FusionCharts实例,指定了图表类型(`type`)、渲染位置(`renderAt`)、宽度(`width`)、高度(`height`)、数据格式(`dataFormat`)以及数据源(`dataSource`)。 #### 四、...
在Java ASP环境中,FusionCharts可以通过Java服务器端组件来使用。ASP(Active Server Pages)是一种服务器端脚本环境,用于生成动态网页。尽管ASP主要与微软的.NET框架关联,但在Java环境中,可以使用类似JSP(Java...
在“FusionCharts示例代码(jsp)”这个主题中,我们将深入探讨如何在JavaServer Pages (JSP)环境中集成并使用FusionCharts。 一、FusionCharts简介 FusionCharts提供了一系列的图表类型,包括柱状图、饼图、线图、...
在本项目中,我们看到使用PHP来调用FusionCharts库,实现了饼状统计图的展示。这涉及到几个关键的知识点: 1. **FusionCharts库**:FusionCharts是一个跨浏览器和跨平台的图表库,支持HTML5/SVG和Flash两种渲染模式...
在本例中,"FusionCharts.dll"是FusionCharts组件的实现,它封装了所有用于生成图表的逻辑和资源。开发者可以通过调用DLL中的方法来实例化图表、设置数据源、定义样式和交互行为等。 标签"fusioncharts dll 文件...
FusionCharts是一款强大的JavaScript图表库,能够...通过以上配置和代码,你可以在Java环境中利用FusionCharts实现图表的服务器端导出。记得在实际开发中根据项目需求调整相关参数,并确保所有依赖项正确配置和引用。
标题中的“使用FusionCharts实现数据库的动态数据交互”指的是使用FusionCharts这款JavaScript图表库与数据库进行数据通信,以实现在网页上展示动态、实时的图表数据。FusionCharts是一款强大的图表解决方案,它提供...
**FusionCharts XT Evaluation** 是一个...在实际项目中,FusionCharts XT 可以通过解压名为"FusionCharts_XT_Evaluation"的压缩包来获取并使用,包括示例代码、文档和其他资源,从而快速上手并实现数据可视化的需求。
本教程将深入探讨FusionCharts的核心概念、安装、配置以及如何在实际项目中应用,旨在帮助初学者快速掌握这个工具。 ### 1. FusionCharts简介 FusionCharts是一个基于Web的图表组件,支持超过90种图表类型,包括...
在Java和JavaScript环境中使用FusionCharts,开发者可以通过以下步骤进行操作: 1. **安装和引入库**:首先需要在项目中引入FusionCharts的JavaScript库,通常通过CDN链接或本地文件引用。 2. **准备数据**:数据...