ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Chinese display in X-Y Chart label
Posted by Sam Chen on Aug-22-2011 16:27
Hi:
I have a problem for displaying chinese in X-Y chart dataset
I get the data to display from a file(save as ansi),and my source code save as utf8
I read the file by this (open Chart,"<encoding(big5)","$ARGV[0]")
and it works at xAxis,yAxis and title but only has the trouble at data name
I set the data name like this $layer->addDataSet($data[$k], -1,$Category[$k])
does someone could help me?
thanks

  Re: Chinese display in X-Y Chart label
Posted by Peter Kwan on Aug-23-2011 01:59
Hi Sam,

Is it possible to provide an example (may be you can modify the "Simple Bar Chart" sample code) together with an example text file, and also include the chart image you obtained?

Some possible reasons that may cause the problem are:

- The titles are using not from the data file, but as string literals in the Perl code (which is saved as UTF8), but the data are from the text file (which is in Big5). The "<encoding(big5)" may just mean to convert the big5 into the "default Perl encoding", which may not be UTF8. (Using a text editor to save a Perl script as UTF8 does not necessarily configures the Perl script to use UTF8 as default encoding. The default encoding can be affected by environmental variables or OS configuration.)

- There may be font issues. Are the data name displayed using a font that is capable of displaying Chinese characters?

By having an example and the chart image you obtain so far, I can probably deduce the cause of the problem and solve it.

Regards
Peter Kwan

  Re: Chinese display in X-Y Chart label
Posted by Peter Kwan on Aug-23-2011 03:58
Hi Sam,

In fact, I think a more reliable method to converting big5 to utf8 is to simply read in the file without specifying any encoding, then use the from_to method of the Perl Encode module to convert the big5 to utf8.

use Encode;
$converted_string = from_to($text_string, "big5", "utf8");

Hope this can help.

Regards
Peter Kwan

  Re: Chinese display in X-Y Chart label
Posted by Sam Chen on Aug-23-2011 10:04
Attachments:
Hi Peter:
sample code like this:
open Chart,"<encoding(big5)","$ARGV[0]" or die "$!";
$c->xAxis()->setLabels($labels); <--Labels is Chinese too,and it's correct
$c->xAxis()->setLabelStyle("kaiu.ttf", 10);
$c->yAxis()->setLabelStyle("arialbd.ttf", 10);
for($k=0;$k<$row-1;$k++){
$layer->addDataSet($data[$k], -1,$Category[$k])->setDataSymbol($k%10, 9,-1,-1);
} <---Here is the problem,Category is wrong

Attach file is my picture and text file,text file only have three lines,all of the data are read
from the text file,except the title name.
Line one is X-Axis name.
Line two and three are my dataset,line two display in English,line three display in Chinese.

buy the way,I try to use encode module,but it still doesn't work
Hope you could help me
thanks a lot

Sam
line.jpg
chart.txt

  Re: Chinese display in X-Y Chart label
Posted by Peter Kwan on Aug-23-2011 13:31
Hi Sam,

Your chart image shows that your Chinese characters are encoded correctly in UTF8, but the legend box is using the font "Arial Bold", which does not support Chinese characters.

To solve the problem, please use a font that can support Chinese characters. For example:

#set the default normal and bold fonts to kaiu.ttf and kaui.ttf bold.
$c->setDefaultFonts("kaiu.ttf", "kaiu.ttf bold");

or

#please specify a Chinese font when you add the legend box
$legendBox = $c->addLegend(60, 60, 0, "kaiu.ttf", 12)->setBackground($perlchartdir::Transparent);

Hope this can help.

Regards
Peter Kwan

  Re: Chinese display in X-Y Chart label
Posted by Sam Chen on Aug-23-2011 13:48
The second it worked!(but why setDefaultFonts doesn't work?)
anyway thanks for helping me