0

For Chart (gantt) ,Chinese Fonts garbled in X/Y,How to solve?

asked 2013-02-27 03:38:36 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-03-04 04:49:39 +0800

vincentjian gravatar image vincentjian
2245 6

For Chart (gantt) ,Fonts garbled in X/Y

Chinese part can not be displayed correctly in ZK Chart

my code

<chart id="gantt" title="Gantt Chart" width="700" height="400" type="gantt" threeD="false" fgAlpha="128" dateFormat="yyyy/MM/dd">
<zscript><![CDATA[
    import org.zkoss.zul.GanttModel.GanttTask;
    public Date date(int year, int month, int day) {
        final java.util.Calendar calendar = java.util.Calendar.getInstance();
        calendar.set(year, month-1, day);
        final Date result = calendar.getTime();
        return result;
    }
    //series, task (task description, start, end, complete percentage)
    GanttModel ganttmodel = new GanttModel();

    ganttmodel.addValue("Actual", new GanttTask("案例xxx", date(2008,4,1), date(2008,4,3), 0.0));
    ganttmodel.addValue("Actual", new GanttTask("Obtain Approval", date(2008,4,9), date(2008,4,9), 0.0));
    ganttmodel.addValue("Actual", new GanttTask("Requirements Analysis", date(2008,4,10), date(2008,5,15), 0.0));
    ganttmodel.addValue("Actual", new GanttTask("Design Phase", date(2008,5,15), date(2008,6,17), 0.0));
    ganttmodel.addValue("案例一", new GanttTask("Design Signoff", date(2008,6,30), date(2008,6,30), 0.0));
    ganttmodel.addValue("Actual", new GanttTask("Alpha Implementation", date(2008,7,1), date(2008,9,12), 0.0));
    ganttmodel.addValue("Actual", new GanttTask("Design Review", date(2008,9,12), date(2008,9,22), 0.0));
    ganttmodel.addValue("Actual", new GanttTask("Revised Design Signoff", date(2008,9,25), date(2008,9,27), 0.0));
    ganttmodel.addValue("Actual", new GanttTask("Beta Implementation", date(2008,8,12), date(2008,9,12), 0.0));
    ganttmodel.addValue("Actual", new GanttTask("Testing", date(2008,10,31), date(2008,11,17), 0.0));
    ganttmodel.addValue("Actual", new GanttTask("Final Implementation", date(2008,11,18), date(2008,12,5), 0.0));
    ganttmodel.addValue("Actual", new GanttTask("Signoff", date(2008,12,10), date(2008,12,11), 0.0));
    gantt.setModel(ganttmodel);
]]></zscript>
</chart>
delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted
0

answered 2013-03-04 04:54:48 +0800

vincentjian gravatar image vincentjian
2245 6

updated 2013-03-04 04:56:57 +0800

Chart component is using JFreeChart which change default font that doesn't support Chinese. Therefore, you should specify font manually to chart component. Also refer to document

<chart .....>
<zscript>
...
gantt.setModel(ganttmodel);
Font font = new Font(Font.SERIF, Font.PLAIN, 11);
//Change font name like "新細明體" in first argument
gantt.setTitleFont(font);
gantt.setLegendFont(font);
gantt.setXAxisFont(font);
gantt.setXAxisTickFont(font);
gantt.setYAxisFont(font);
gantt.setYAxisTickFont(font);
...
</zscript>
</chart>
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-02-27 03:38:36 +0800

Seen: 15 times

Last updated: Mar 04 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More