我想将数据库中的数据放入图表中。我尝试了不同的方法,但没有结果。我尝试使用这种简单的方法,但什么也不显示: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
}
图表.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>