Q:Display Chinese error in JFreeChart ,ok in JasperReport!
-
- Posts: 4
- Joined: Tue Jan 13, 2004 7:14 am
Q:Display Chinese error in JFreeChart ,ok in JasperReport!
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!
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!
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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.
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 4
- Joined: Tue Jan 13, 2004 7:14 am
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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?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?
Have you tried generating the chart on its own, outside of JasperReport?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


I've a question about Chinese,too
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?
i.e. turn "SHANGHAI" to "S
H
A
N
G
H
A
I"(in Chinese character)
any suggestions?
-
- Posts: 4
- Joined: Tue Jan 13, 2004 7:14 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!
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!
-
- Posts: 4
- Joined: Tue Jan 13, 2004 7:14 am
display chinese in JFreeChart
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
--------------------------------------------------------------------------------
看到网上不少关于在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