Produce graphics reports using JFreeChart
Bromon original, please respect the copyright
First, demand analysis
My leaders believe that there should be more scientific decision-making models on the issue of marrying me for my wife. If you can quantify daily emotional life, you can provide data support for her decision with time to generate a data report. Based on the basic principles of leadership, this software has been developed to provide new ideas for family information construction.
Second, the system overview
The basic function of this system is to receive the user's daily input and save, the month / quarter / annual end chart, the cycle ring is hosted. Since the investment is limited (not letting me pay for it, it is very good), so the Software version 1.0 uses a single-machine application, use the Access database. If the market promotion is good, it does not exclude the possibility of launching large FRP software (KIN RELATION MANAGE, family relationship management), HA (House Automatization, home automation), using a powerful J2EE framework Provide a complete solution for family information construction.
The target picture effect generated by the program is as follows:
Third, system requirements
1. Open source toolkit JFreeChart-1.0.0-pre1.jar and the toolkit itself to use JCOMMON-1.0.0.0.0-pre1.jar
Download address: http://sourceforge.net/projects/jfreechart/
2, girlfriend one.
Please prepare your own, don't provide download
The following main story is how the system extracts data from the database and then generates a graphical report. (I finally entered the topic.)
Data table structure:
Curve_id water number automatic growth
Curve_owner varchar (30) Distinguish your husband's data or the data of your wife
Curve_cent Double Double Score
Curve_Year INT year
CURVE_MONTH INT Month
Curve_day Int Day
Note Text Remarks
The values used to encapsulate each score are as follows:
Package org.bromon.fiona.curve.da d; import java.util. *;
Public Class Curvevo
{
PRIVATE INT YEAR;
PRIVATE INT MONTH;
PRIVATE INT DAY;
PRIVATE DOUBLE CENT;
PRIVATE STRING NOTE;
Private string ooner;
// Get / set method
..........
}
The key code for generating pictures is as follows:
Package org.bromon.fiona.curve.util; // a big pile of import
Public Class Drawpic
{
/ **
* According to the time query data, encapsulate the obtained data into the TimeSeriesCollection object.
* TimeSeriesCollection is an object of classes defined in JFreeChart
* This method will be called later DRAW method
* @ param int to query which year
* @ param int to query?
* @ Return TimeSeriesCollection
* /
Public TimeSeriescollection getData (int year, int month)
{
// Fiona's data collection, where the Curvevo value objects defined above are stored.
/ / These values of these values are from the database, the relevant code is the most common JDBC content, please complete it yourself.
List dataoffiona = new arraylist ();
// bromon data set
List dataofbromon = new arraylist ();
/ / Conformably the object to return
TimeSeriescollection result = new timeSeriescollection ();
// These two objects respectively correspond to a curve, the parameters of the constructor, will be displayed below the picture.
TimeSeries Fiona = New TimeSeries ("Fiona");
TimeSeries Bromon = New TimeSeries ("Bromon");
Curvevo CV = NULL;
// Traverse Fiona's data set, fill Fiona objects
For (int i = 0; i { CV = (curvevo) DataOffiona.get (i); Fiona.add (New Day (Cv.getDay (), CV.getMonth (), CV.GETYEAR ()), New Double (CV.getcent ()))))) } Result.addSeries (Fiona); For (int i = 0; i { CV = (curvevo) DataOfbromon.get (i); Bromon.add (New TimeSeriesDataItem (New Day (Cv.getDay (), CV.getMonth (), CV.GETYEAR ()), New Double (CV.getcent ())))))) } Result.Addseries (bromon); } / / Generate the method of the chart, the chart data is from the getData method above Public String Draw (int y, int m) { String result = null; String title = "Love chart" of Bromon & Fiona; String subtitle = y "year" m "month"; String domain = "time"; // x axis String Range = "Score"; // Y-axis TimeSeriescollection Data = this.getdata (Y, M); JFreeChart Chart = ChartFactory.createtimeSerieschart (Title, Domain, Range, Data, True, True, False) TextTitle Subtitle = New TextTitle (Subtitle, New Font ("Song", Font.Bold, 20); Chart.addsubtitle (SUBTITE); Chart.Settitle (New TextTitle (Title, New Font ("Song", Font.Italic, 20)); Chart.SetBackground (New GradientPaint (0, 0, Color.White, 0, 1000, Color.White)); C.SETTIME (New Date ()); String filename = "c: // pics //" y "" m ".jpg"; // Save as position Try { File f = new file ("c: // pics"); IF (! f.exists ()) { f.mkdir (); } Chartutilities.savechartasjpeg (New File (Filename), 100, Chart, 1000, 600); // Width 1000, high 600 } catch (Exception E) { E.PrintStackTrace (); } Result = filename; Return Result; } // ok, test Public static void main (string args []) { NEW DRAWPIC (). DRAW (2005, 3); } } Generate the related content of the ring-composite chart, and put it after finishing. JFreechart's drawing is very powerful, but the API's writing is very uncomfortable, and many elements are not easy. If there is a better API, I am very willing to use, of course, free is a very important premise.