首 页 | 新 闻 | 技术中心 | 第二书店 | 《程序员》 | 《开发高手》 | 社 区 | 黄 页 | 人 才
移 动专 题SUNIBM微 软微 创精 华Donews人 邮
我的技术中心 
我的分类 我的文档
全部文章 发表文章
专栏管理 使用说明



 RSS 订阅 
最新文档列表
Windows/.NET
.NET  (rss)    
Visual C++  (rss)    
Delphi  (rss)    
Visual Basic  (rss)    
ASP  (rss)    
JavaScript  (rss)    
Java/Linux
Java  (rss)    
Perl  (rss)    
综合
其他开发语言  (rss)    
文件格式  (rss)    
企业开发
游戏开发  (rss)    
网站制作技术  (rss)    
数据库
数据库开发  (rss)    
软件工程
其他  (rss)    

积极原创作者 
iiprogram (68)
qdzx2008 (50)
goodboy1881 (14)
wangchinaking (58)
fancyhf (1)
harrymeng (41)
yjz0065 (113)
coofucoo (105)
Drate (69)
lphpc (30)
CSDN - 文档中心 - Java 阅读:1460   评论: 0    参与评论
标题   jfreechart使用及其向linux移植     选择自 sswt 的 Blog
关键字   jfreechart使用及其向linux移植
出处  

jfreechart

jfreechart是一个免费(文档收费40$)创建图片的java工具.可以创建如下图形:
饼图(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;

必看的几个贴:

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移植的时候会显示不出中文,出现方块。

解决方法: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

然后对自己基于jfreechart写的程序进行重新编译、运行:

javac -encoding GBK   BarChartDemo.java //以GBK进行编码
java -Djava.awt.headless=true BarChartDemo//使用awt时不用调用x11的图形环境

 

在tomcat使用jfreechart时

tomcat是5.0,在redhat8上,未启动X,方法如下:
1)终止你的tomcat。即:
tomcat目录/bin/shutdown.sh
2)设置环境变量:
CATALINA_OPTS="-Djava.awt.headless=true"
export CATALINA_OPTS
(如果你想每次开机自动生效,则可把这两句写入系统或者你的账号启动sh的.profile里)
3)启动你的tomcat。即:
tomcat目录/bin/startup.sh

用的Web服务器resin时,

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


 

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

最近项目中用到jfreechart,使用的版本是:jfreechart-0.9.8。
如果不进行相关的font的设置,生成的统计图表显示的中文非常模糊。
做了一个例子,可以解决这个问题。

[该方法是将一般字体替换为“黑体”使中文更加清楚,

因此必须保证你的OS上有该字体,并且jdk能够识别得到]

核心代码如下:

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);

 


相关文章
对该文的评论