简体   繁体   中英

Issues with the primefaces bar chart

im trying to get the primefaces bar chart to work however i am getting the following error :

java.lang.ClassCastException: java.util.Vector cannot be cast to org.primefaces.model.chart.CartesianChartModel


WARNING:   StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.ClassCastException: java.util.Vector cannot be cast to org.primefaces.model.chart.CartesianChartModel
    at org.primefaces.component.chart.bar.BarChartRenderer.encodeData(BarChartRenderer.java:127)
    at org.primefaces.component.chart.bar.BarChartRenderer.encodeScript(BarChartRenderer.java:51)
    at org.primefaces.component.chart.bar.BarChartRenderer.encodeEnd(BarChartRenderer.java:36)

here is the code:

        <p:barChart id="basic" value="#{markingBean.studentsMarks}" legendPosition="ne"  
                    title="Basic Bar Chart" min="0" max="200" style="height:300px"/>

the studentsMarks is retrieved from a backing bean that does a db query

        studentsMarks = markingFacade.getMarksForStudent(markToEdit);

and the db query to get the 13 marks i need :

  public List getMarksForStudent(Marking id) {
    System.out.println("In getMarksForStudent");
    System.out.println("id = " + id);
    System.out.println("id = " + id.getId());
    Query m = em.createQuery("SELECT m.markSectionOne, m.markSectionTwo, m.markSectionThree, m.markSectionFour, m.markSectionFive, m.markSectionSix, m.markSectionSeven, m.markSectionEight, m.markSectionNine, m.markSectionTen, m.markSectionEleven, m.markSectionTwelve, m.markSectionThirteen FROM MARKING m WHERE m.id = :id", Double.class);
    m.setParameter("id", id.getId()); // Note the getId()
    System.out.println(m);     
    return m.getResultList();

}

what is causing the error and how can i fix it ?

Thanks guys :)

Thank for clear question!

<p:barChart require org.primefaces.model.chart.CartesianChartModel value. You assign List type, so jvm will show java.lang.ClassCastException exception.

See the link below, and follow it:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM