我第一次使用primefaces并且我能够使用硬编码的数字显示饼图像这样:
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.primefaces.model.chart.PieChartModel;
/**
*
* @author Stanley
*/
@ManagedBean(name = "chartBean")
@RequestScoped
public class ChartBean implements Serializable {
private PieChartModel pieModel;
public ChartBean() {
createPieModel();
}
public PieChartModel getPieModel() {
return pieModel;
}
private void createPieModel() {
pieModel = new PieChartModel();
pieModel.set("Branch1", 540);
pieModel.set("Branch2", 325);
pieModel.set("Branch3", 702);
//Feed these values from the database dynamically
}
}
我有一个查询,可以动态地从数据库中为所有分支提取相同的信息,如下所示:
select branch_code, count(*) accounts_opened from account_master where acct_opn_date
>= trunc(sysdate,'mm')
group by branch_code;
我的问题是如何使用数据库中的我的值在此饼图上显示相同的信息?
答案 0 :(得分:1)
您可以从oracle获取值并从Resulset中设置值。
喜欢这个
Connection con = YOUR_CONNECTION;
PreparedStatment ps = con.prepareStatment(YOU SELECT);
ResultSet result = ps.executeQuery();
while (result.next())
{
pieModel.set(result.getSting("branch_code"), result.gtInt("accounts_opened "));
}