Q:Display Chinese error in JFreeChart ,ok in JasperReport!

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
littlebean
Posts: 4
Joined: Tue Jan 13, 2004 7:14 am

Q:Display Chinese error in JFreeChart ,ok in JasperReport!

Post by littlebean » Tue Jan 13, 2004 8:14 am

I have searching the posters before, but I am still puzzling.

It is strange that under Windows they both ok.
I import and implement the JFreeChart in JasperReport, and then
both display Simplfied Chinese Ok.

When under linux, after importing the iTextAsian.jar , setting the X11 enviroment, setting the encoding when connecting DB and revsing the encoding format in xml file , Chinese in JapserReport display ok, while
Chinese in JFreeChart, for example : x axis, y axis lables and Legends
display error.

I check the fonts under $JAVAHOME/jre/lib , but I do not know which font I should add, since I use the default font in JFreeChart.
I do not know the default font for Chinese is which one.
Can you tell me that?


Is there any different requirements for the display of Chinese in JasperReport and JFreeChart? Need I do anything else for JFreeChart?

Thanks a lot!

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Jan 13, 2004 8:59 pm

The thing to bear in mind when displaying general Unicode characters in JFreeChart is that you must specify a font that supports those characters. Most fonts don't support the full range. This URL has some info:

http://www.alanwood.net/unicode/fonts.html

Presumably if JasperReports is working, then you do have a suitable font - you just need to find out what it is, then set your chart up to use it.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

littlebean
Posts: 4
Joined: Tue Jan 13, 2004 7:14 am

Post by littlebean » Wed Jan 14, 2004 2:22 am

In fact, I have tried that.
In JasperReport I use the font: SimSun

And I use the following sentence to test whether it is useful, but failed.
chart.setTitle(new TextTitle("中文", new Font("SimSun", Font.PLAIN, 15)));

It still displays error.

Is there any other thing I need to check?

Thanks a lot!

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jan 14, 2004 10:20 pm

littlebean wrote:In fact, I have tried that.
In JasperReport I use the font: SimSun

And I use the following sentence to test whether it is useful, but failed.
chart.setTitle(new TextTitle("中文", new Font("SimSun", Font.PLAIN, 15)));

It still displays error.

Is there any other thing I need to check?
That should work (for the chart title, but you'd need to set the font for the axis labels separately). What error do you get? Is it just placeholder characters, or do you get an exception?

Have you tried generating the chart on its own, outside of JasperReport?
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

du wei
Posts: 2
Joined: Sat Nov 29, 2003 6:34 am

I've a question about Chinese,too

Post by du wei » Sat Jan 17, 2004 6:59 am

I wanna the axis label to be
i.e. turn "SHANGHAI" to "S
H
A
N
G
H
A
I"(in Chinese character)
any suggestions?

littlebean
Posts: 4
Joined: Tue Jan 13, 2004 7:14 am

Post by littlebean » Sat Jan 17, 2004 9:35 am

I tried to use jsp and javabean to draw a JFreeChat to Jpeg file directly under linux,
while the title which should be Chinese is insteaded by rectangle.

When I compile the .java and run the jsp , there is no error.

I do not know what happened.
There is something wrong but I cannot find it.

The following is the code of BarChartDemo.java:

package scriptlets;
import java.io.*;
import java.awt.*;
import java.awt.font.*;

import org.jfree.data.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.axis.*;

public class BarChartDemo {

public JFreeChart draw() throws IOException{

CategoryDataset dataset = getDataSet2();
JFreeChart chart = ChartFactory.createBarChart3D(
"", //title
"水果", // category axis
"产量", // value axis
dataset,
PlotOrientation.VERTICAL, //
true,
false,
false );
chart.setTitle(new TextTitle("水果图", new Font("SimSun", Font.PLAIN, 15)));

FileOutputStream fos_jpg = null;
try {
fos_jpg = new FileOutputStream("fruit.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,400,300,null);
} finally {
try {
fos_jpg.close();
} catch (Exception e) {}
}
return chart;
}

private static CategoryDataset getDataSet2() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(100, "北京", "苹果");
dataset.addValue(200, "北京", "梨子");
dataset.addValue(300, "北京", "葡萄");
return dataset;
}
}


Thanks a lot! Puzzling!

littlebean
Posts: 4
Joined: Tue Jan 13, 2004 7:14 am

Post by littlebean » Fri Jan 30, 2004 10:40 am

Thanks a lot!
Finally, resolve that!

The method for JasperReport to display Chinese under linux
is different with that for JFreeChart!

Guest

Post by Guest » Tue Feb 24, 2004 8:42 am

could you tell us how you resolve this problem?
thx

chechao

display chinese in JFreeChart

Post by chechao » Tue May 17, 2005 7:33 am

JFreeChart在Linux下的中文问题,没有经过验证,转贴来自Matrix,希望能有所参考。
--------------------------------------------------------------------------------
看到网上不少关于在linux上面不能正确显示java程序中中文的问题,最近作一个BS应用,部署tomcat到linux后,用jfreechart做的图表不能正确显示中文字体.
经过我的摸索研究,通过以下步骤,可以顺利解决这个问题.

1.copy XFree86-libs-4.2.1-13.73.3.i386.rpm,ttfm-1.0-6.i386.rpm到linux,
用rpm -i 文件名 安装这2个rpm包.
2.copy gbsn00lp.ttf到 %jdk所在目录%/jre/lib/fonts/ 下面.
3.修改 %jdk所在目录%/jre/lib/fonts/ 下面的fonts.dir文件,第一行数值加1,在最后一行加上:
gbsn00lp.ttf -Arphic Technology Co.-AR PL SungtiL GB-medium-r-normal--0-0-0-0-c-0-iso10646-1
4.修改 %jdk所在目录%/jre/lib/ 目录下面的font.properties文件(如果系统为中文环境,那么是font.properties_zh).
将字体名全部替换成 -Arphic Technology Co.-AR PL SungtiL GB-medium-r-normal--0-0-0-0-c-0-iso1064-1,
在文件的末尾加上:
filename.song_medium_r=gbsn00lp.ttf
filename.song_medium_i=gbsn00lp.ttf
filename.song_bold_r=gbsn00lp.ttf
filename.song_bold_i=gbsn00lp.ttf
filename.fangsong_medium_r=gbsn00lp.ttf
filename.fangsong_medium_i=gbsn00lp.ttf
filename.fangsong_bold_r=gbsn00lp.ttf
filename.fangsong_bold_i=gbsn00lp.ttf
filename.kai_medium_r=gbsn00lp.ttf
appendedfontpath=%jdk所在目录%/jre/lib/fonts

cox
Posts: 1
Joined: Fri Nov 04, 2005 11:06 am

Post by cox » Sun Nov 06, 2005 2:12 pm

could you tell us how you resolve this problem?

myepoch
Posts: 23
Joined: Tue Mar 28, 2006 8:23 am

Post by myepoch » Tue Jun 06, 2006 2:02 am

i meet the same problem,too.
could you tell us how you resolve this problem?

myepoch
Posts: 23
Joined: Tue Mar 28, 2006 8:23 am

Post by myepoch » Tue Jun 06, 2006 4:26 am

why , can nobody help me?

Locked