Jfreechart Experience Summary (for version: jfreechart-1.0.0-pre2.zip)
Problem 1: An exception is thrown every time a jfreechar image is generated. The exception indicates that the problem lies in chartfactory. createxylinechart (picname, "timeline", "data", xydataset, true, true, false) on this line of code (or create another type of chart)
Analysis: jfreechart uses a Java AWT image library. Therefore, make sure that the JVM runs in headless mode. If jfreechar is used in Unix systems, add-djava. AWT. Headless = true/to run and start in the Catalina. Sh file in the bin directory of Tomcat/
Problem 2: Garbled Chinese Characters in jfreechart images generated on UNIX systems
Analysis: There are two possible garbled characters:
One is the question mark (?) in Chinese (?), This is generally because of an error in Chinese character encoding conversion. You must change setenv lc_ctype iso_8859_1 to setenv lc_ctype zh in the. cshrc file of the current user in the Unix system.
One is to display the text box (□), which is generally because the font used in jfreechart does not exist in the current UNIX system. All fonts used in the jfreechart package are as follows:
New font ("sansserif", 1, 12)
New font ("foo", 1, 9)
New font ("Arial", 0, 10)
New font ("dialog", 0, 12)
New font ("bitstream Vera sans", 0, 11)
Among them, the new font ("bitstream Vera sans", 0, 11) font is used to comment on the color lines. This Font does not exist in UNIX systems, you need to install the font or modify the package Org. jfree. chart. this font appears in the constructor of the labelblock file in the block.
Question 3: Time Display format in the image timeline generated by jfreechart
Analysis: When two or more groups of data charts are generated, there are two types of data:
One is that both X and Y axes are only data, you can directly use chartfactory. createxylinechart (picname, "X axis data", "Y axis data", xydataset, true, true, false). xydataset collects data obtained by xyseries through xyseriescollection:
Xyseries [] xyseries = new xyseries [count];
For (INT I = 0; I <count; I ++ ){
Xyseries [I] = new xyseries (name [I]);
}
Xyseries [1]. Add (double arg0, double arg1 );
Xyseries [2]. Add (double arg0, double arg1 );
Both groups of data must be transmitted in double-precision format. x and y-axis data in the chart are also displayed in double-precision format.
One is that the X axis data is time, and the Y axis data is a data with certain precision corresponding to this time. In this case, chartfactory must be used. createtimeserieschart (picname, "timeline", "data", xydataset, true, true, false). xydataset is used to collect data obtained by Timeseries through timeseriescollection:
Timeseries [] = new Timeseries [count];
For (INT I = 0; I <count; I ++ ){
Timeseries [I] = new Timeseries (name [I], minute. Class );
}
Timeseries [0]. addorupdate (new minute (minute, hour, date, month, year), double arg1 );
Timeseries [1]. addorupdate (new minute (minute, hour, date, month, year), double arg1 );
(Note: Here addorupdate is used instead of ADD. If add is used, data is sent once to generate a chart image, when this method is called somewhere else to generate a chart image, an exception message of data conflict is reported. It is estimated that the data sent last time has not been cleared, so to prevent this situation, we usually use addorupdate)
The two groups of data are sent in pairs (time and double precision data). The X axis is a timeline and is displayed in a common time format, the displayed time format can be customized in the Code. The detailed code is as follows:
Dateaxis = (dateaxis) xyplot. getdomainaxis ();
Dateaxis. setdateformatoverride (New simpledateformat ("Time Format "));
Another thing to note is that the time precision displayed on the timeline can be set according to your own needs. The maximum value can be accurate to the year, and the minimum value can be accurate to the millisecond, the set location is in Timeseries [I] = new Timeseries (name [I], minute. class) in the Code, the current precision is set to minute (Minute. class), all optional accuracy is as follows: Year. class month. class Week. class Day. class hour. class minute. class seconds. class millisecond. class, and then in Timeseries [0]. addorupdate (new minute (minute, hour, date, month, year), double arg1) code can also be adjusted accordingly.