jfreechart是一個(gè)免費(fèi)(文檔收費(fèi)40$)創(chuàng)建圖片的java工具.可以創(chuàng)建如下圖形:
餅圖(pie charts;)
曲線圖(line charts )
柱狀圖(horizontal/vertical bar charts)
甘特圖(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;

必看的幾個(gè)貼:

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

在向linux移植的時(shí)候會(huì)顯示不出中文,出現(xiàn)方塊。

解決方法:copy或引用/usr/share/fonts/zh_CN/TrueType目錄下的中文字體,修改/home/jdk/jre/lib/fonts.properties

配置文件,如下:

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

然后對(duì)自己基于jfreechart寫(xiě)的程序進(jìn)行重新編譯、運(yùn)行:

javac -encoding GBK   BarChartDemo.java //以GBK進(jìn)行編碼
java -Djava.awt.headless=true BarChartDemo//使用awt時(shí)不用調(diào)用x11的圖形環(huán)境

 

在tomcat使用jfreechart時(shí),

tomcat是5.0,在redhat8上,未啟動(dòng)X,方法如下:
1)終止你的tomcat。即:
tomcat目錄/bin/shutdown.sh
2)設(shè)置環(huán)境變量:
CATALINA_OPTS="-Djava.awt.headless=true"
export CATALINA_OPTS
(如果你想每次開(kāi)機(jī)自動(dòng)生效,則可把這兩句寫(xiě)入系統(tǒng)或者你的賬號(hào)啟動(dòng)sh的.profile里)
3)啟動(dòng)你的tomcat。即:
tomcat目錄/bin/startup.sh

用的Web服務(wù)器resin時(shí),

修改resin/bin/下面的wrapper.pl中的一行
$JAVA_ARGS="-Djava.awt.headless=true";


 

==============================================================

最近項(xiàng)目中用到j(luò)freechart,使用的版本是:jfreechart-0.9.8。
如果不進(jìn)行相關(guān)的font的設(shè)置,生成的統(tǒng)計(jì)圖表顯示的中文非常模糊。
做了一個(gè)例子,可以解決這個(gè)問(wèn)題。

[該方法是將一般字體替換為“黑體”使中文更加清楚,

因此必須保證你的OS上有該字體,并且jdk能夠識(shí)別得到]

核心代碼如下:

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("隸書(shū)", 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);