Jfreechart
Jfreechart is a free Java tool for creating images (documentation charges 40 $). You can create images such:
Pie Chart (pie charts ;)
Line charts)
Column chart (horizontal/vertical bar charts)
Gantt Chart (Gantt charts ;)
XY plots and scatter plots;
Time series, high/low/open/close charts and candle stick charts;
Combination charts;
Pareto charts;
Bubble charts;
Wind plots, meter charts and symbol charts;
Several notes:
Http://www-900.ibm.com/developerWorks/cn/wsdd/library/techarticles/yangyaping0307/waslinux.shtml
Http://www.lslnet.com/linux/docs/linux-2940.htm
Http://blog.blogchina.com/article_81038.344426.html
When porting to Linux, there will be no Chinese characters and a square will appear.
Solution: copy or reference the Chinese font in the/usr/share/fonts/zh_cn/TrueType directory, and modify/home/JDK/JRE/lib/fonts. properties.
The configuration file is as follows:
Sansserif.0 =-misc-ZYSong18030-medium-r-normal -- *-% d-*-C-*-iso10646-1
Sansserif. italic.0 =-misc-ZYSong18030-medium-r-normal -- *-% d-*-C-*-iso10646-1
Sansserif. bold.0 =-misc-ZYSong18030-medium-r-normal -- *-% d-*-C-*-iso10646-1
Sansserif. bolditalic.0 =-misc-ZYSong18030-medium-r-normal -- *-% d-*-C-*-iso10646-1
# Component font character encodings
#
Fontcharset. serif.0 = sun. Io. chartobyteiso8859_1
Fontcharset. serif.1 = sun. AWT. motif. chartobytex11gbk
Fontcharset. sansserif.0 = sun. Io. chartobyteiso8859_1
Fontcharset. sansserif.1 = sun. AWT. motif. chartobytex11gbk
Fontcharset. monospaced.0 = sun. Io. chartobyteiso8859_1
Fontcharset. monospaced.1 = sun. AWT. motif. chartobytex11gbk
Fontcharset. dialog.0 = sun. Io. chartobyteiso8859_1
Fontcharset. dialog.1 = sun. AWT. motif. chartobytex11gbk
Fontcharset. dialoginput.0 = sun. Io. chartobyteiso8859_1
Fontcharset. dialoginput.1 = sun. AWT. motif. chartobytex11gbk
Fontset. sansserif. Plain =/
-Misc-ZYSong18030-medium-r-normal -- *-% d-*-C-*-iso10646-1
Fontset. sansserif. italic =/
-Misc-ZYSong18030-medium-r-normal -- *-% d-*-C-*-iso10646-1
Fontset. sansserif. Bold =/
-Misc-ZYSong18030-medium-r-normal -- *-% d-*-C-*-iso10646-1
Fontset. sansserif. bolditalic =/
-Misc-ZYSong18030-medium-r-normal -- *-% d-*-C-*-iso10646-1
Fontset. Default =/
-Misc-ZYSong18030-medium-r-normal -- *-% d-*-C-*-iso10646-1
Appendedfontpath =/usr/share/fonts/zh_cn/TrueType
Then re-compile and run the program written based on jfreechart:
Javac-encoding GBK barchartdemo. Java // encoded in GBK
Java-djava. AWT. Headless = true barchartdemo // you do not need to call the X11 graphic environment when using AWT.
When Tomcat uses jfreechart,
Tomcat is 5.0. On redhat8, X is not started. The method is as follows:
1) terminate your tomcat. That is:
Tomcat directory/bin/shutdown. Sh
2) Set environment variables:
Catalina_opts = "-djava. AWT. Headless = true"
Export catalina_opts
(If You Want to automatically take effect at startup, you can write these two statements into the system or the. profile of your account to start Sh)
3) Start your tomcat. That is:
Tomcat directory/bin/startup. Sh
When the Web server resin is used,
Modify a row in wrapper. pl under resin/bin/
$ Java_args = "-djava. AWT. Headless = true ";
========================================================== ======================================
Jfreechart is used in recent projects with the version: jfreechart-0.9.8.
If you do not set the relevant font, the generated Statistical Chart displays very vague Chinese characters.
An example is provided to solve this problem.
[This method replaces the General font with the "" to make Chinese clearer,
Therefore, you must ensure that your OS has this font and JDK can recognize it.]
The core code is as follows:
Jfreechart chart = chartfactory. createverticalbarchart3d (title, domain, range, dataset, true, true, false );
Chart. setbackgroundpaint (New gradientpaint (0.0f, 0.0f, color. White, 1000f, 0.0f, color. Red ));
Chart. settitle (New texttitle (title, new font ("", Font. italic, 15 )));
Font font = new font ("", Font. truetype_font, 12 );
Standardlegend legend = (standardlegend) Chart. getlegend ();
Legend. setitemfont (font );
Categoryplot plot = (categoryplot) Chart. getplot ();
Plot. setforegroundalpha (0.9f );
Categoryaxis domain_axis = plot. getdomainaxis ();
Domain_axis.setticklabelfont (font );
Valueaxis value_axis = plot. getrangeaxis ();
Value_axis.setticklabelfont (font );