Hi
I am using primefaces5,tomcat6 for my application.
I have tried charts but in that linechart is not working,am tried with showcase example.
Its giving the following exception
com.sun.faces.mgbean.ManagedBeanCreationException:
com.sun.faces.spi.InjectionProviderException
java.lang.reflect.InvocationTargetException
java.lang.ClassCastException: org.primefaces.model.chart.CartesianChartModel cannot be cast to org.primefaces.model.chart.LineChartModel
How to solve this issue?
Thanks in advance
regards
Veda
Line chart not displaying
manager.xhml page
CahrtBean.java class
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<p:chart type="line" model="#{chartBean.lineModel1}" style="height:300px;"/>
</h:body>
</html>
Code: Select all
package com.mq.cms.web.generic.controller;
import javax.annotation.PostConstruct;
import org.primefaces.model.chart.Axis;
import org.primefaces.model.chart.AxisType;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.CategoryAxis;
import org.primefaces.model.chart.ChartSeries;
import org.primefaces.model.chart.LineChartModel;
import org.primefaces.model.chart.LineChartSeries;
public class ChartBean {
private LineChartModel lineModel1;
private LineChartModel lineModel2;
@PostConstruct
public void init() {
createLineModels();
}
public LineChartModel getLineModel1() {
return lineModel1;
}
public LineChartModel getLineModel2() {
return lineModel2;
}
private void createLineModels() {
lineModel1 = (LineChartModel) initLinearModel();
lineModel1.setTitle("Linear Chart");
lineModel1.setLegendPosition("e");
Axis yAxis = lineModel1.getAxis(AxisType.Y);
yAxis.setMin(0);
yAxis.setMax(10);
lineModel2 = initCategoryModel();
lineModel2.setTitle("Category Chart");
lineModel2.setLegendPosition("e");
lineModel2.setShowPointLabels(true);
lineModel2.getAxes().put(AxisType.X, new CategoryAxis("Years"));
yAxis = lineModel2.getAxis(AxisType.Y);
yAxis.setLabel("Births");
yAxis.setMin(0);
yAxis.setMax(200);
}
private CartesianChartModel initLinearModel() {
CartesianChartModel model = new CartesianChartModel();
LineChartSeries series1 = new LineChartSeries();
series1.setLabel("Series 1");
series1.set(1, 2);
series1.set(2, 1);
series1.set(3, 3);
series1.set(4, 6);
series1.set(5, 8);
LineChartSeries series2 = new LineChartSeries();
series2.setLabel("Series 2");
series2.set(1, 6);
series2.set(2, 3);
series2.set(3, 2);
series2.set(4, 7);
series2.set(5, 9);
model.addSeries(series1);
model.addSeries(series2);
return model;
}
private LineChartModel initCategoryModel() {
LineChartModel model = new LineChartModel();
ChartSeries boys = new ChartSeries();
boys.setLabel("Boys");
boys.set("2004", 120);
boys.set("2005", 100);
boys.set("2006", 44);
boys.set("2007", 150);
boys.set("2008", 25);
ChartSeries girls = new ChartSeries();
girls.setLabel("Girls");
girls.set("2004", 52);
girls.set("2005", 60);
girls.set("2006", 110);
girls.set("2007", 90);
girls.set("2008", 120);
model.addSeries(boys);
model.addSeries(girls);
return model;
}
}
Regards
Veda
Web Developer
Veda
Web Developer
Great that the cce is gone, but you should be able to fix errors like the cce yourself. Regarding the npe, again check/debug YOUR code to see if something is null. Basic java debugging skills,nothing specific for PF
-
- Information
-
Who is online
Users browsing this forum: No registered users and 34 guests