我正在尝试使用zk框架(JFreeChart)绘制拨号图表。请在下面找到代码:
chart1Dial.zul
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="new page title" border="normal">
<hlayout spacing="10px" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('demo.chart.dial.DialChartVM')">
<chart id="chartC" width="250" height="250"
paneColor="#ffffff" type="dial"
model="@bind(vm.celsiusModel)" engine="@bind(vm.engine)"/>
<!-- <chart id="chartF" width="250" height="250"
paneColor="#ffffff" type="dial"
model="@bind(vm.fahrenheitModel)"/> -->
</hlayout>
</window>
</zk>
ChartData.Java :
package demo.chart.dial;
import java.awt.Color;
import org.zkoss.zul.DialModel;
import org.zkoss.zul.DialModelScale;
import demo.chart.ChartColors;
public class ChartData {
public static DialModel createCelsiusModel(){
DialModel model = new DialModel();
model.setFrameFgColor("#808080");
model.setFrameBgAlpha(255);
model.setFrameBgColor("#FFFFFF");
model.setFrameBgColor1("#000000");
model.setFrameBgColor2("#000000");
model.setCapRadius(0.1);
model.setGradientDirection("vertical");
return model;
}
public static int toFahrenhit(int celsius){
return Math.round(celsius * 9 / 5 + 32);
}
public static int toCelsius(int fahrenheit){
return Math.round((fahrenheit - 32) * 5 / 9);
}
}
DialChartEngine.Java
package demo.chart.dial;
import org.jfree.chart.JFreeChart;
import org.zkoss.zkex.zul.impl.JFreeChartEngine;
import org.zkoss.zul.Chart;
import org.zkoss.zul.DialModel;
import org.zkoss.zul.DialModelScale;
import java.awt.Color;
import demo.chart.ChartColors;
public class DialChartEngine extends JFreeChartEngine {
private boolean explode = false;
public boolean prepareJFreeChart(JFreeChart jfchart, Chart chart) {
DialModel model = new DialModel();
DialModelScale scale = model.newScale(-10.0, 60.0, 230, -280, 10.0, 4);
//scale's configuration data
scale.setValue(27);
scale.setText("Celsius");
scale.newRange(-10, 0, ChartColors.toHtmlColor(Color.getHSBColor(0.55f, 0.8f, 1)), 0.61, 0.603);
scale.newRange( 0, 10, ChartColors.toHtmlColor(Color.getHSBColor(0.3f , 0.8f, 1)), 0.61, 0.603);
scale.newRange( 10, 20, ChartColors.toHtmlColor(Color.getHSBColor(0.18f, 0.8f, 1)), 0.61, 0.603);
scale.newRange( 20, 30, ChartColors.toHtmlColor(Color.getHSBColor(0.12f, 0.8f, 1)), 0.61, 0.603);
scale.newRange( 30, 40, ChartColors.toHtmlColor(Color.getHSBColor(0.08f, 0.8f, 1)), 0.61, 0.603);
scale.newRange( 40, 50, ChartColors.toHtmlColor(Color.getHSBColor(0.05f, 0.8f, 1)), 0.61, 0.603);
scale.newRange( 50, 60, ChartColors.toHtmlColor(Color.getHSBColor(0.0f , 0.8f, 1)), 0.61, 0.603);
scale.setTickColor("#FFFFFF");
scale.setNeedleType("pin");
scale.setNeedleColor("#FF0000");
return true;
}
public void setExplode(boolean explode) {
this.explode = explode;
}
}
DialChartVM.Java
package demo.chart.dial;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zul.DialModel;
public class DialChartVM {
DialModel celsiusModel;
DialChartEngine engine;
public DialModel getCelsiusModel() {
return celsiusModel;
}
/*public DialModel getFahrenheitModel() {
return fahrenheitModel;
}*/
public DialChartEngine getEngine() {
return engine;
}
@Init
public void init() {
int celsius = 27;
celsiusModel = ChartData.createCelsiusModel();
engine = new DialChartEngine();
}
}
当我尝试执行以下代码时,我收到一条错误消息:
尚不支持的图表类型:拨打
以下是 错误 :
org.zkoss.zk.ui.UiException: Unsupported chart type yet: dial
at org.zkoss.zkex.zul.impl.JFreeChartEngine.getChartImpl(JFreeChartEngine.java:242)
at org.zkoss.zkex.zul.impl.JFreeChartEngine.drawChart(JFreeChartEngine.java:266)
at org.zkoss.zul.Chart.doSmartDraw(Chart.java:243)
at org.zkoss.zul.Chart.access$100(Chart.java:82)
at org.zkoss.zul.Chart$SmartDrawListener.onEvent(Chart.java:224)
at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2746)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2717)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2658)
at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1765)
at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1550)
at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:512)
at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:356)
at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:215)
at org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
请告诉我如何进一步处理。谢谢
答案 0 :(得分:0)
我现在能够绘制拨号盘,因为我已经下载了所有zk-jar(版本8)
请在下面找到我的工作代码:
<强> chart1Dail.zul 强>
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="new page title" border="normal">
<hlayout spacing="10px" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('demo.chart.dial.DialChartVM')">
<chart id="chartC" width="250" height="250"
paneColor="#ffffff" type="dial"
model="@bind(vm.celsiusModel)" />
</hlayout>
</window>
</zk>
<强> DialChartVM.java 强>
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zul.DialModel;
public class DialChartVM {
DialModel celsiusModel;
public DialModel getCelsiusModel() {
return celsiusModel;
}
@Init
public void init() {
int celsius = 50;
celsiusModel = ChartData.createCelsiusModel(celsius);
}
}
<强> ChartData.Java 强>
import java.awt.Color;
import org.zkoss.zul.DialModel;
import org.zkoss.zul.DialModelScale;
import demo.chart.ChartColors;
public class ChartData {
public static DialModel createCelsiusModel(int value){
DialModel model = new DialModel();
DialModelScale scale = model.newScale(-10.0, 60.0, 230, -280, 10.0, 4);
//scale's configuration data
scale.setValue(value);
scale.setText("Celsius");
scale.newRange(-10, 0, ChartColors.toHtmlColor(Color.getHSBColor(0.55f, 0.8f, 1)), 0.61, 0.603);
scale.newRange( 0, 10, ChartColors.toHtmlColor(Color.getHSBColor(0.3f , 0.8f, 1)), 0.61, 0.603);
scale.newRange( 10, 20, ChartColors.toHtmlColor(Color.getHSBColor(0.18f, 0.8f, 1)), 0.61, 0.603);
scale.newRange( 20, 30, ChartColors.toHtmlColor(Color.getHSBColor(0.12f, 0.8f, 1)), 0.61, 0.603);
scale.newRange( 30, 40, ChartColors.toHtmlColor(Color.getHSBColor(0.08f, 0.8f, 1)), 0.61, 0.603);
scale.newRange( 40, 50, ChartColors.toHtmlColor(Color.getHSBColor(0.05f, 0.8f, 1)), 0.61, 0.603);
scale.newRange( 50, 60, ChartColors.toHtmlColor(Color.getHSBColor(0.0f , 0.8f, 1)), 0.61, 0.603);
scale.setTickColor("#FFFFFF");
scale.setNeedleType("pin");
scale.setNeedleColor("#FF0000");
model.setFrameFgColor("#808080");
model.setFrameBgAlpha(255);
model.setFrameBgColor("#FFFFFF");
model.setFrameBgColor1("#000000");
model.setFrameBgColor2("#000000");
model.setCapRadius(0.1);
model.setGradientDirection("vertical");
return model;
}
public static int toFahrenhit(int celsius){
return Math.round(celsius * 9 / 5 + 32);
}
public static int toCelsius(int fahrenheit){
return Math.round((fahrenheit - 32) * 5 / 9);
}
}
我删除了 DialChartEngine.Java 文件。