网上找了很多方法,除了这个方法,其他的要么麻烦要么好使

JFreeChart默认字体有"Arial", "Dialog", "Dialog", "SansSerif", "Tahoma"

而需要用到是宋体等中文字体时,JVM找不到相关字体文件,所以会显示乱码,解决方法如下。

方法一:
复制所使用的中文字体文件(如simsun.ttc)到此目录中(如果没有fallback目录,请手动建立。)
$JAVA_HOME/jre/lib/fonts/fallback

为何要建立fallback目录参照sequence.fallback的说明:
If the runtime environment has a directory lib/fonts/fallback and this directory contains valid TrueType or Type 1 fonts, the runtime automatically adds these fonts as fallback fonts for 2D rendering. On Windows, if there is a system EUDC (End User Defined Characters) font registered with Windows, the runtime automatically adds this font as well as a fallback font for 2D rendering

方法二:
将Linux系统的字体目录作为JDK下面的一个字体目录连接。

ln -s $FONTS_PATH/FONT_DIR $JAVA_HOME/jre/lib/fonts/fallback


simsun下载地址:http://www.cr173.com/font/42194.html

Logo

更多推荐