-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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.
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>
Asked: 2009-04-29 01:45:55 +0800
Seen: 1,322 times
Last updated: Jan 08 '10