I. Requirement Analysis
My leadership believes that there should be a more scientific decision-making model on whether to marry me as a wife. If we can quantify the daily emotional life and generate data reports based on the time x axis, we can provide data support for her decision-making. Adhering to the basic principle guided by the will of leadership, this software has been developed to provide new ideas for family informatization construction.
Ii. System Overview
The basic function of the system is to receive and save daily input by users, and generate a line chart and a period-over-period column chart at the month, quarter, or end of the year. Due to limited investment (it is good not to let me pay out), version 1.0 of this software uses a single-Host application and Access database. If the market conditions are good, It is not ruled out that the launch of large FRP software (Family Resource Project) may include KRM (Kin Relation Manage, Family relationship management), HA (House automation, household Automation) and other modules, using a powerful J2EE framework, provide a complete solution for household information construction.
The target image generated by the program is as follows:
Iii. System Requirements
1. Open source toolkit jfreechart-1.0.0-pre1.jar and the toolkit jcommon-1.0.0-pre1.jar it wants to use
: Http://sourceforge.net/projects/jfreechart/
2. One girlfriend.
Please prepare for the download.
The following describes how the system extracts data from the database and generates a graphical report. (I finally got into the question .)
Data Table Structure:
| Curve_id |
Serial number |
Automatic Growth |
| Curve_owner |
Varchar (30) |
Identify husband data or wife data |
| Curve_cent |
Double |
Day score |
| Curve_year |
Int |
Year |
| Curve_month |
Int |
Month |
| Curve_day |
Int |
Day |
| Note |
Text |
Remarks |
The value object used to encapsulate each score is as follows:
Package org. bromon. fiona. curve. dao;
Import java. util .*;
Public class CurveVo
{
Private int year;
Private int month;
Private int day;
Private double cent;
Private String note;
Private String owner;
// Get/set Method
............
}
The key code for generating an image is as follows:
Package org. bromon. fiona. curve. util;
// A large number of import
Public class DrawPic
{
/**
* Query data by time and encapsulate the obtained data into a TimeSeriesCollection object
* TimeSeriesCollection is the object of the class defined in JfreeChart.
* This method will be called by the following draw Method
* @ Param int indicates the year to be queried.
* @ Param int: Which month is to be queried?
* @ Return TimeSeriesCollection
*/
Public TimeSeriesCollection getData (int year, int month)
{
// Fiona data set, which stores the previously defined CurveVo Value Object
// The value of these value objects comes 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 ();
// Construct the object to return
TimeSeriesCollection result = new TimeSeriesCollection ();
// The two objects correspond to a curve respectively. The constructor parameters are displayed below the image.
TimeSeries fiona = new TimeSeries ("fiona ");
TimeSeries bromon = new TimeSeries ("bromon ");
CurveVo cv = null;
// Traverse the Fiona dataset and fill in the fiona object
For (int I = 0; I <dataOfFiona. size (); I ++)
{
Cv = (CurveVo) dataOfFiona. get (I );
Fiona. add (new TimeSeriesDataItem (new Day (cv. getDay (), cv. getMonth (), cv. getYear (), new Double (cv. getCent ())));
}
Result. addSeries (fiona );
For (int I = 0; I <dataOfBromon. size (); 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 );
}
// Chart generation method. The chart data comes from the above getData method.
Public String draw (int y, int m)
{
String result = null;
String title = "Bromon & Fiona's love trend chart ";
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 ("", Font. BOLD, 20 ));
Chart. addSubtitle (subtitle );
Chart. setTitle (new TextTitle (title, new Font ("", Font. ITALIC, 20 )));
Chart. setBackgroundPaint (new GradientPaint (0, 0, Color. white, 0, 1000, Color. white ));
C. setTime (new Date ());
String fileName = "c: \ pics \" + y + "" + m + ". jpg"; // save as a location
Try
{
File f = new File ("c: \ pics ");
If (! F. exists ())
{
F. mkdir ();
}
ChartUtilities. saveChartAsJPEG (new File (fileName), 100, chart, 1000,600); // width: 1000, height: 600
} Catch (Exception e)
{
E. printStackTrace ();
}
Result = fileName;
Return result;
}
// OK, test it
Public static void main (String args [])
{
New DrawPic (). draw );
}
}
Generate the relevant content of the period-over-period column chart, sort it out, and release it.
JfreeChart has powerful plotting functions, but it is uncomfortable to write APIs in some places. It is difficult to customize many elements. If there is a better API, I would like to use it. Of course, free is a very important prerequisite.