Preface: WebWork is one of the popular J2EE's major architectures. In the actual project, we tend to call a chart Chart in the output stream of Webwork, instead of direct output with Response.out. So how should we do it? This article will explain in detail the application of JFreeChart in Webwork. This paper debugging environment is Windows2000 Tomcat5.0. A total of three parts: 1. JFreeChart introduction 2, WebWork Introduction and Webwork, JFreeChart Applications 3, JFreeChart's Application of Application in Webwork 1: JFreechart Introduction: JFreeChart is open source project, it is mainly used Various charts include: pie chart, histogram (ordinary column chart, stack column), line diagram, regional diagram, distribution map, mixing chart, Gantt chart, and some instrument panels, etc. I. The basic knowledge of JFreeChart creates a web chart is mainly consisting of three classes: org.jfree.chart.servlet.chartdeleterorog.jfree.chart dervlet.displayChartorg.jfree.chart.Servlet.ServletUtilities are simply introduced below : Chartdeleter inherits from httpsessionBindingListener for implementation When the session is closed, delete the image file in the temporary cat. ServletUTILITIES has a series of methods: SaveChartas *; SaveChartas * is stored as an image in different forms; the SendTempFile method is overloaded many times, used to send the file stream to response; DisplayChart inherits from httpservlets to process display images; 2: WebWork Introduction and Webwork, JFreeChart Application Environment Configuration WebWork is an open web application framework for simplifying web-based applications. The greatest advantage of Webwork is its simplicity and flexibility. Webwork has a small API that enables developers to develop work quickly. WebWork is a combination of many features and applicability, including using Variour View technology, such as JavaServer Pages (JSP), Velocity, Extensible Stylesheet Language Transformations Specification (XSLT), and JasperReporters. Also, Webwork has very good support to JFreeChart. Download Webwork-2.0-beta2.zip from here. (
https://webwork.dev.java.net/servlets/projectdocumentlistListListListListListListListListListListListListListList
) Unpack files, you can find JFreeChart-0.9.13.jar in the web-2.0 / lib / optional directory. You can also download the latest JFreeChart-0.9.15.zip from here. (
http://www.jfree.org/jfreechart/index.html
) This article uses JFreeChart-0.9.15.zip. Directory structure diagram of the web application as follows: / WebApp / Web-INF /WEBAPP/Web-inf/web.xml /Webapp/web-inf/webwork.tld / webApp / web-inf / class / webapp / web-inf /classes/xwork.xml / webapp / web-inf / lib Next Please be sure to put the following packages under the / WebApp / Web-INF / LIB directory. 1. Commons-logging.jar 2. OGNL-2.5.1.jar 3. Oscore-2.2.1.jar 4. XWORK-1.0-beta.jar 5. WebWork-2.0-beta.ja Next is a package that can be selected, specifically determined whether to add: cos-multipart.jar pell-multiple.jar velocity-dep-1.3.jar2.1 Configure your xwork.xml file image As in the following example, be careful to include WebWork-Default.xml.
Steps: First at xwork.xml - define result-type Description: Switch the Chart file into the output stream obtained by httpservletresponse * object Output in the browser p> * author: Pawpaw * @version 1.0 12/15/2003 * / public class ChartResult implements Result {JFreeChart chart; boolean chartSet = false; private int height; private int width; public void setChart (JFreeChart chart) {this.chart = chart; chartSet = true;} // set the image length public void setHeight (int height) {this.height = height;} // set the width of the image public void setWidth (int width) {this.width = width;} public void execute (ActionInvocation invocation) throws Exception {JFreeChart chart = null ; If (chartset) {chart = this.Chart;} else {chart = (jfreechart) Invocation.getStack (). FindValue ("chart");} if (chart == null) {throw new nullpointRexception ("no chart found ");} // Strong file streams into output streams obtained by HTTPSERVLETRESPONSE objects HttpServletResponse response = ServletActionContext.getResponse (); OutputStream os = response.getOutputStream (); ChartUtilities.writeChartAsPNG (os, chart, width, height); os.flush ();}} Create JFreeChart action class. Package paw.test; import java.awt.insets; import java.awt.font; import java.io.printwriter; import javax.servlet.http.httpsession; import org.jfree.data. *; import org.jfree.chart Import.plot. *; import org.jfree.chart.entity. *; import org.jfree.chart.urls. *; import org.jfree.chart.servlet. *; import org. JFree.Chart.Labels.standardPietooltipGenerator; import Org.jfree.util.Rotation; import com.opensymphony.xwork.actionsupport; / * * Description: Output a slash chart p> * author: Pawpaw * @version 1.0 12/15/2003 * / Public class viewModerationchartAction Extends ActionSupport; public string execute () throws exception {// Create a Chart file data set XYSeries DataSeries = new xyseries (null); for (int i = 0; i <= 100; i ) {dataseries.add (i, randomutils.nextint ());} xyseriescollection xydataset = new xyseriescollection (dataseries); valueaxis xaxis = New NumBeraxis ("Raw Marks"); // X Bar Coordinate Valueaxis Yaxis = New Numbraxis ("MODERATED MARKS"); // Y Bearings // Setting CHART Style Chart = New Jfreechart ("Modression Function", // Chart title JFreeChart.default_title_font, new xyplot (XyDataSet, Xaxis, Yaxis, New StandardxyItemRenderer (StandardxyItemRenderer (StandardxyItemRenderer (StandardxyItemRereMrendere (StandardxyItemRenderer (STANDARDREITETEER.LINES)), // Data Set False // Generate URL Link ); Chart.setbackgroundpaint (java.awt.color.white); // Setting the background color font font = new font ("black body", font.center_baseline, 20); // Set the font and size of the picture title Texttitle _title = new texttitle; _title.setfont (font); chart.settitle; return super.success;} public jfreechart getchart () {return chart;}} Summary: This is just a simple example, if If you want to know in depth, you can refer to the Webwork documentation and the JFreeChart website. Reference: http://www.jfree.org/jfreechart/index.html Webwork English documentation