我第一次使用素数,并且能够使用像这样的硬编码图形显示饼图:
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;
我的问题是,如何使用数据库中的“我的值”在此饼图中显示相同的信息?
最佳答案
您可以从oracle获取值,并从Resultset设置值。
像这样
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 "));
}