0

ZK 3.6.1: Chinese characters in Chart can't shown, all becomes squares

asked 2009-04-29 01:45:55 +0800

lovetide gravatar image lovetide
169 1 7

Usually, I put newest JFreeChart library to ${Tomcat_Home}/lib. I download JFreeChart from sf.net, not the one in ZK.

After the release of JFreeChart-1.0.11, they change their default font to 'Tahoma' which show Chinese characters as squares. So I keep using JFreeChart-1.0.10 until ZK 3.6.1 is released.

When I put ZK 3.6.1 library and JFreeChart-1.0.10 library to ${Tomcat_Home}/lib, restart tomcat, browsing .zul page, Tomcat return a HTTP 500 error:

HTTP Status 500 - 

--------------------------------------------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: Servlet execution threw an exception
	filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:122)


root cause 

java.lang.NoClassDefFoundError: org/jfree/chart/entity/JFreeChartEntity
	org.zkoss.zkex.zul.impl.JFreeChartEngine.drawChart(JFreeChartEngine.java:335)
	org.zkoss.zul.Chart$1.onEvent(Chart.java:214)
	org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:197)
	org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:141)
	org.zkoss.zk.ui.impl.EventProcessingThreadImpl.process0(EventProcessingThreadImpl.java:488)
	org.zkoss.zk.ui.impl.EventProcessingThreadImpl.run(EventProcessingThreadImpl.java:422)


root cause 

java.lang.ClassNotFoundException: org.jfree.chart.entity.JFreeChartEntity
	java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	java.security.AccessController.doPrivileged(Native Method)
	java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	java.lang.ClassLoader.loadClass(ClassLoader.java:252)
	java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	org.zkoss.zkex.zul.impl.JFreeChartEngine.drawChart(JFreeChartEngine.java:335)
	org.zkoss.zul.Chart$1.onEvent(Chart.java:214)
	org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:197)
	org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:141)
	org.zkoss.zk.ui.impl.EventProcessingThreadImpl.process0(EventProcessingThreadImpl.java:488)
	org.zkoss.zk.ui.impl.EventProcessingThreadImpl.run(EventProcessingThreadImpl.java:422)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.


So I think ZK 3.6.1 can't work with JFreeChart-1.0.10, and I put jfreechat library shipped with ZK to ${Tomcat_Home}/lib, .zul webpage works, but the chinese characters in Chart can't shown now.

After JFreeChart-1.0.11 is released, I've post a feature request "More control on Chart" here
http://sourceforge.net/tracker/?func=detail&aid=2131896&group_id=152762&atid=785194, hope them can be implemented, or I must stay at Zk 3.6.0 to get a normal Chart.

delete flag offensive retag edit

3 Replies

Sort by » oldest newest

answered 2009-04-29 09:25:21 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

extends JFreeChartEngine and override prepareJFreeChart(JFreeChart jfchart, Chart chart).

link publish delete flag offensive edit

answered 2009-04-30 05:03:48 +0800

lovetide gravatar image lovetide
169 1 7

Thanks a lot henrichen!

I wrote a sample, wish it can help others:

<?xml version='1.0' encoding='UTF-8'?>
<?page title='Chart tweak test'?>
<zk>
<chart id='chartTweakTest' type='bar' title=''/>

<grid width='500px'>
	<rows>
		<row>Title 标题<textbox id='title' value='Chart Tweak Test 图表调节测试' width='20em' onChange='GenerateChart()'/></row>
		<row>
			<html><![CDATA[
				Title font <br/>
				标题字体
			]]></html>
			<hbox>
				<combobox id='fontname_Title' value='黑体' onChange='GenerateChart()'>
					<comboitem label='Courier New'/>
					<comboitem label='FixedSys'/>
					<comboitem label='MS Sans Serif'/>
					<comboitem label='Tahoma'/>
					<comboitem label='Times New Roman'/>
					<comboitem label='宋体'/>
					<comboitem label='仿宋_GB2312'/>
					<comboitem label='黑体'/>
					<comboitem label='楷体_GB2312'/>
					<comboitem label='隶书'/>
				</combobox>
				<intbox id='fontsize_Title' value='18' onChange='GenerateChart()'/>
				<checkbox id='fontbold_Title' label='Bold 粗体' onCheck='GenerateChart()'/>
				<checkbox id='fontitalic_Title' label='Italic 斜体' onCheck='GenerateChart()'/>
			</hbox>
		</row>
		<row>
			<html><![CDATA[
				Legend font <br/>
				图例字体
			]]></html>
			<hbox>
				<combobox id='fontname_Legend' value='宋体' onChange='GenerateChart()'>
					<comboitem label='Courier New'/>
					<comboitem label='FixedSys'/>
					<comboitem label='MS Sans Serif'/>
					<comboitem label='Tahoma'/>
					<comboitem label='Times New Roman'/>
					<comboitem label='宋体'/>
					<comboitem label='仿宋_GB2312'/>
					<comboitem label='黑体'/>
					<comboitem label='楷体_GB2312'/>
					<comboitem label='隶书'/>
				</combobox>
				<intbox id='fontsize_Legend' value='12' onChange='GenerateChart()'/>
				<checkbox id='fontbold_Legend' label='Bold 粗体' onCheck='GenerateChart()'/>
				<checkbox id='fontitalic_Legend' label='Italic 斜体' onCheck='GenerateChart()'/>
			</hbox>
		</row>
		<row><label/><checkbox id='showLegend' checked='true' label='Show legend 显示图例' onCheck='GenerateChart()'/></row>
		<row>
			<html><![CDATA[
				Axis tick font <br/>
				刻度线字体
			]]></html>
			<hbox>
				<combobox id='fontname_Axis' value='宋体' onChange='GenerateChart()'>
					<comboitem label='Courier New'/>
					<comboitem label='FixedSys'/>
					<comboitem label='MS Sans Serif'/>
					<comboitem label='Tahoma'/>
					<comboitem label='Times New Roman'/>
					<comboitem label='宋体'/>
					<comboitem label='仿宋_GB2312'/>
					<comboitem label='黑体'/>
					<comboitem label='楷体_GB2312'/>
					<comboitem label='隶书'/>
				</combobox>
				<intbox id='fontsize_Axis' value='12' onChange='GenerateChart()'/>
				<checkbox id='fontbold_Axis' label='Bold 粗体' onCheck='GenerateChart()'/>
				<checkbox id='fontitalic_Axis' label='Italic 斜体' onCheck='GenerateChart()'/>
			</hbox>
		</row>
		<row><label/><hbox><checkbox id='showValueAxix2' checked='true' label='Show second value axis 显示第二条数值轴线' onCheck='GenerateChart()'/></hbox></row>
		<row><label/><hbox><checkbox id='showAxixLine' label='Show axis line 显示轴线' onCheck='GenerateChart()'/><checkbox id='showTickMark' checked='true' label='Show tick marks 显示刻度线' onCheck='GenerateChart()'/></hbox></row>
		<row><label/><checkbox id='antialias' label='AntiAlias(Smooth edge) 边缘平滑' onCheck='GenerateChart()'/></row>
		<!--<row><label/><button label='Refresh chart' onClick='GenerateChart()'/></row>-->
	</rows>
</grid>

<zscript><![CDATA[

import java.awt.Font;

SimpleCategoryModel chartData = new SimpleCategoryModel ();
chartTweakTest.setModel (chartData);

public class MyChartEngine extends org.zkoss.zkex.zul.impl.JFreeChartEngine
{
	public boolean prepareJFreeChart (org.jfree.chart.JFreeChart jfchart, Chart chart)
	{
		Font titleFont = new Font(fontname_Title.value, Font.PLAIN | (fontbold_Title.checked?Font.BOLD:Font.PLAIN) | (fontitalic_Title.checked?Font.ITALIC:Font.PLAIN), fontsize_Title.value.intValue());
		Font legendFont = new Font(fontname_Legend.value, Font.PLAIN | (fontbold_Legend.checked?Font.BOLD:Font.PLAIN) | (fontitalic_Legend.checked?Font.ITALIC:Font.PLAIN), fontsize_Legend.value.intValue());
		Font axisFont = new Font(fontname_Axis.value, Font.PLAIN | (fontbold_Axis.checked?Font.BOLD:Font.PLAIN) | (fontitalic_Axis.checked?Font.ITALIC:Font.PLAIN), fontsize_Axis.value.intValue());

		jfchart.getTitle().setFont (titleFont);

		jfchart.getLegend().setItemFont (legendFont);
		jfchart.getLegend().setVisible (showLegend.checked);

		jfchart.getCategoryPlot().getDomainAxis().setTickLabelFont (axisFont);
		jfchart.getCategoryPlot().getRangeAxis().setTickLabelFont (axisFont);
		jfchart.getCategoryPlot().getDomainAxis().setLabelFont (axisFont);
		jfchart.getCategoryPlot().getRangeAxis().setLabelFont (axisFont);

		jfchart.getCategoryPlot().getDomainAxis().setAxisLineVisible (showAxixLine.checked);
		jfchart.getCategoryPlot().getRangeAxis().setAxisLineVisible (showAxixLine.checked);
		jfchart.getCategoryPlot().getDomainAxis().setTickMarksVisible (showTickMark.checked);
		jfchart.getCategoryPlot().getRangeAxis().setTickMarksVisible (showTickMark.checked);

		if (showValueAxix2.checked)
		{
			org.jfree.chart.axis.ValueAxis valueAxis2 = new org.jfree.chart.axis.NumberAxis ();
			valueAxis2.setTickLabelFont (axisFont);
			valueAxis2.setLabelFont (axisFont);
			valueAxis2.setAxisLineVisible (showAxixLine.checked);
			valueAxis2.setTickMarksVisible (showTickMark.checked);
			valueAxis2.setRange (0, 20000000);
			jfchart.getCategoryPlot().setRangeAxis (1, valueAxis2);
		}

		jfchart.setAntiAlias (antialias.checked);

		//true  to tell this engine NOT to apply its default rendering properties;
		//false to tell this engine TO apply its default rendering properties.
		return false;
	}
}
MyChartEngine chartEngine = new MyChartEngine ();
chartTweakTest.setEngine (chartEngine);


public void GenerateChart ()
{
	chartTweakTest.setTitle (title.value);
	chartData.clear ();
	for (int i=1; i<=3; i++)
	{
		chartData.setValue (
			"Population 人口",
			"City 城市 " + i,
			Double.valueOf(Math.random()*100)
			);
		chartData.setValue (
			"GDP",
			"City 城市 " + i,
			Double.valueOf(Math.random()*100)
			);
	}
}

GenerateChart ();

]]></zscript>

</zk>

link publish delete flag offensive edit

answered 2010-01-08 05:24:21 +0800

jentrees gravatar image jentrees
51 1

A simple way like that:

java.awt.Font zh_font = new java.awt.Font("SimSun", 10, 15);

chartTweakTest.setTitleFont(zh_font);
chartTweakTest.setLegendFont(zh_font);

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2009-04-29 01:45:55 +0800

Seen: 1,322 times

Last updated: Jan 08 '10

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