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

Message ListMessage List     Post MessagePost Message

  Unable to get Japanese character display in Python 2.7
Posted by Somik Raha on Jan-11-2012 10:12
Hi,

I am using ChartDirector to create charts with Japanese titles. For example,

c = pychartdir.XYChart(...)
c.setPlotArea(...)
title = unicode("プロジェクトの価値開発の成功与えられた").encode('utf-8')
print "title: %s" %(title)
c.yAxis().setTitle(title, "arial.ttf", 16)

This code is not working. I have tried all sorts of combinations including:
title = "プロジェクトの価値開発の成功与えられた"

and

title = repr("プロジェクトの価値開発の成功与えられた")

but this code produces a chart without any title. When using repr(), I see escaped strings
and not actual Japanese characters.

I have verified according to your documentation that site-packages has the file arial.ttf.

Any pointers would be much appreciated.

Thank you so much.

Regards,
Somik

  Re: Unable to get Japanese character display in Python 2.7
Posted by Peter Kwan on Jan-11-2012 23:40
Hi Somik,

Note that the Arial font (arial.ttf) does not contain Japanese characters. To display Japanese characters, please use a font that can have Japanese characters, such as Ming Liu (mingliu.ttc), Ms Mincho (msmincho.ttf), etc.

If the above still does not solve the problem, is it possible to attach your exact python code file, and also the chart you get so far. I need the Python code file to check the encoding you are using.

(Your existing code first uses the "unicode" function to change the text string in your source code to unicode, then uses the "encode" method to change the unicode to UTF8. If Python cannot understand the encoding of your source code in the first place, it may convert it to unicode incorrectly. The chart image, even if it just contains "garbage characters" of empty squares, may help to diagnose the exact cause of the problem.)

Hope this can help.

Regards
Peter Kwan

  Re: Unable to get Japanese character display in Python 2.7
Posted by Somik Raha on Jan-12-2012 03:20
Thanks, Peter. I found the source of the problem - my fonts needed to be in ChartDirector's
font folder. I used the Arial Unicode font (ARIALUNI.TTF) that comes with Windows and was
able to display Japanese characters properly.