Souha
Souha

Reputation: 63

put datas from database to chart primefaces

I want to put datas from database to chart primefaces. I try with different methods but without result. i try with this simple method but dosen't display nothing: ManagedBean:

public class ChartBean implements Serializable{
    private List < ChartContentBean > chartContentbeanList;

    public ChartBean() {
        chartContentbeanList = new ArrayList < ChartContentBean > ();
        chartContentbeanList.add(new ChartContentBean(2006, 25, 20));
        chartContentbeanList.add(new ChartContentBean(2007, 60, 50));
        chartContentbeanList.add(new ChartContentBean(2008, 40, 65));
        chartContentbeanList.add(new ChartContentBean(2009, 70, 60));
    }
    public List < ChartContentBean > getChartContentbeanList() {
        return chartContentbeanList;
    }
}  

ChartContentBean.xhtml

public class ChartContentBean{
    private int year;
    private int passPercentage;
    private int failedPercentage;

    public ChartContentBean() {}
    public ChartContentBean(int year, int passPercentage, int failedPercentage) {
        this.year = year;
        this.passPercentage = passPercentage;
        this.failedPercentage = failedPercentage;
    }
    //get and set
}

chart.xhtml

<xmlns:p="http://primefaces.prime.com.tr/ui">
<h:form>
  <p:lineChart value="#{chartBean.chartContentbeanList}" var="chartContentBean" xfield="#{chartContentBean.year}">
    <p:chartSeries label="Class A"
    value="#{chartContentBean.passPercentage}" />
    <p:chartSeries label="Class B"
    value="#{chartContentBean.failedPercentage}" />
  </p:lineChart>
</h:form>

Upvotes: 0

Views: 1152

Answers (2)

klimpond
klimpond

Reputation: 766

Use the CartesianChartModel class from primefaces package in your bean to provide data to your charts in a JSF page. There is no element <p:chatSeries> in Primefaces 3.x as far as I know.

Upvotes: 0

Tankhenk
Tankhenk

Reputation: 634

Well take a look at http://www.primefaces.org/showcase/ui/barChart.jsf in the primefaces showcase is a nice example what you want to achieve. If you follow the showcase you will see what you're missing.

Upvotes: 1

Related Questions