如何创建一个饼图,显示每个人注册的内容数量? [英] How do I create a pie chart that displays the quantity of something registered by each someone?
问题描述
在我的项目中,我想在饼图中显示每位员工在系统中注册的机构数量。
机构表包含一个外键,其中包含注册该机构的员工的ID,因此每个机构都有一个与之相关的员工。
In my project, I want to display in the pie chart how many institutions each employee registered in the system. The institutions table contains a foreign key with the id of the employee who registered the institution, so every institution has an employee associated with it.
我建立了以下代码,但无法进一步:
I built the following code, but couldn't go further:
//etc
String query = "SELECT i.ins_id, f.fun_nome FROM instituicao i " +
"JOIN funcionario f " +
"ON(f.fun_id = i.ins_fun_id)";
PreparedStatement stmt = ConexaoDAO.con.prepareStatement(query,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery();
while(rs.next()) {
total = rs.getInt(1);
}
DefaultPieDataset pieDataset = new DefaultPieDataset();
for(VFuncionarioVO vo : lista) {
//pieDataset.setValue(vo.getNome(), );
}
//etc
我尝试使用GROUP BY在查询中,但没有解决问题。
I tried using GROUP BY in the query, but that didn't solve the problem.
编辑:实际上,此作业需要使用GROUP BY语句。请阅读接受的答案及其评论。
EDIT: actually, using the GROUP BY statement is necessary for this job. Please read the accepted answer and its commentaries.
推荐答案
您不需要 PreparedStatement
。使用 org.jfree .data.jdbc.JDBCPieDataset
接受查询的构造函数返回两列中的数据,第一列包含 VARCHAR
数据,以及第二个包含数字数据。您可以在 ChartFactory
中使用数据集。
You don't need the PreparedStatement
. Use the org.jfree.data.jdbc.JDBCPieDataset
constructor that accepts a query "that returns data in two columns, the first containing VARCHAR
data, and the second containing numerical data." You can use the dataset in your ChartFactory
.
JDBCPieDataset ds = new JDBCPieDataset(conn, "SELECT ...");
这篇关于如何创建一个饼图,显示每个人注册的内容数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!