Line chart not displaying

UI Components for JSF
Post Reply
esm
Posts: 36
Joined: 22 Aug 2012, 08:06

25 Jul 2014, 13:56

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
Regards
Veda
Web Developer

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

25 Jul 2014, 14:48

Code?

esm
Posts: 36
Joined: 22 Aug 2012, 08:06

30 Jul 2014, 05:58

manager.xhml page

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>

CahrtBean.java class

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

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

30 Jul 2014, 08:53

uhhhmmmm you do this cast explicitly yourself... check the methodcalls from the postconstruct onwards

esm
Posts: 36
Joined: 22 Aug 2012, 08:06

30 Jul 2014, 09:26

Hi
thank you for ur reply.

I did the casting explictly but still getting rendering exception
Regards
Veda
Web Developer

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

30 Jul 2014, 14:17

I meant that if you REMOVE it, is the CCE gone to?

esm
Posts: 36
Joined: 22 Aug 2012, 08:06

31 Jul 2014, 07:22

hi
Yes CCE is gone but getting the following exception

java.lang.NullPointerException
at org.primefaces.component.chart.renderer.LineRenderer.encodeData(LineRenderer.java:35)
Regards
Veda
Web Developer

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

31 Jul 2014, 07:38

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

esm
Posts: 36
Joined: 22 Aug 2012, 08:06

05 Aug 2014, 06:29

hi kukeltje
That is working if i take LineChartModel instead of CartesianChartModel


Regards
Veda
Regards
Veda
Web Developer

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 34 guests