Turn from: http://guoyiqi.javaeye.com/blog/247661 First, Introduction Jfreechart is a Jfreechart company on the open source website SourceForge.net A project, is a Java graphics solution (application/applet/servlet/jsp). Second, install the configuration The current latest version is jfreechart-1.0.3, the package to be downloaded: Jfreechart-1.0.3.zip (Project package) Jfreechart-1.0.3-javadocs.zip (API reference documentation) 1, first decompression jfreechart-1.0.3.zip, and focus on three files: Jfreechart-1.0.3.jar, Jcommon-1.0.6.jar, Gnujaxp.jar (This package does not guide, may cause a warning) 2, then the above three documents are examined respectively: %java_home%/lib and the corresponding project/web-inf/lib 3. Configure environment variable Classpath 4, in the/web-inf/web.xml file to join <servlet> <servlet-name>DisplayChart</servlet-name> <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class> </servlet> <servlet-mapping> <servlet-name>DisplayChart</servlet-name> <url-pattern>/servlet/DisplayChart</url-pattern> </servlet-mapping> Three, Function introduction Pie charts (2D and 3D): Pie chart (flat and stereo) Bar charts (regular and stacked, with a optional 3D effect): Histogram Line and area charts: graphs Time series, high/low/open/close charts and candle stick charts: sequence diagram Graphics can be exported into PNG and JPEG format Four, now has encapsulated the model has Two-dimensional moment graph three-dimensional moment graph two-dimensional pie chart three-dimensional pie chart line-like sequence diagram time series diagram V. Implementation of chart generation steps 1, the creation of DataSet object generation 2, the creation of Jfreechart object generation 3, the Urlgenerator control generation VI. Principle The generated Jfreechart object is generated as a stream to generate temporary files in PNG format or in JPEG format, and can then be accessed for requests. Interfaces and classes that may be used in the implementation of chart generation Org.jfree.chart.JFreeChart: Chart Object class Org.jfree.data.category.XXXDataSet: DataSet object class Org.jfree.chart.plot.XXXPlot chart Area Object class Org.jfree.chart.axis.XXXAxis: Axis Object class Org.jfree.chart.render.XXXRender: Modifier Brush Object class Refer to (API reference documentation) Viii. examples 1. How to get Data set: 1 by way of JDBC, by accessing the encapsulation class Createdatasetfromjdbc.java Readpiedata (String sql) method to obtain a pie chart dataset Readcategorydata (String sql) to obtain a moment graph dataset Readxydata (String sql) to get the sequence table data set Mainly write the corresponding SQL statements. 2 The data is obtained by the way of its own, and then the data set SetValue (comparable key, number value) SetValue (number value, comparable rowkey, comparable columnkey) 2 inherits the method in the base class Basecharturlgenerator and implements the interface Controlurlgenerator. (Modeled on existing patterns) for Web applications This will be used to encapsulate the method class Chartplotrender, Createchart, Labelgenerator IX. recommendations Write a Subcharturlgenerator class for each module that applies the Jfreechart chart (inherited from Basecharturlgenerator) Details can be dealt with in the workload chart. Xi. Detailed design process (1) Getting dataset datasets It is easier to determine whether data acquisition is to be assembled using SQL statements, or to get it by yourself in other ways, and then put it in a dataset. If the former, you may only need to write good SQL, and then call the encapsulated CREATEDATASETFROMJDBC can get the dataset, this is of course, for the application of data simple. If it's the latter, you need to imitate me. Example of the graph processing in the work query of the quality safety station get the dataset, first get the data in its own way, then write a class method that sets the passed data one set to the dataset. (2) Get the chart object Jfreechart Write a method for different types of charts, using encapsulated Createchart classes and datasets obtained from the previous step to generate the corresponding chart. and to match the Title,citatory,value parameter to the chart. (3) Chart object representation For references in Web pages, you might consider creating a subclass of the Basecharturlgenerator class that inherits the self-installed (you can consider putting it into this class with the first two steps), and implement the interface Controlurlgenerator write a control method for its specific control, and refer to the Jfreechart object of the step, call the existing method Setcharturl (request, chart); |