Eu tenho uma tabela chamada “CHANGES” e nela tem um campo chamado STATUS, que tem 3 strings definidas: OK, NOK, CAN
Ao fazer o gráfico do primefaces no estilo pie eu consigo trazer as 3 strings descritas no piechart, porem nao mostra a porcentagem no grafico… não estou conseguindo entender como fazer para aparecer a quantidade de OK, NOK e CAN
Exemplo:
OK = 10
NOK = 26
CAN = 1
Alguem poderia me ajudar?
Bean
@ManagedBean(name="changesBeanCharts")
@ViewScoped
public class ChangesBeanCharts implements Serializable {
private PieChartModel pieModel;
public PieChartModel getPieModel() {
return pieModel;
}
public void setPieModel(PieChartModel pieModel) {
this.pieModel = pieModel;
}
public void listar() {
ChangesDaoImplCharts dao;
List<Changes> lista;
try {
dao = new ChangesDaoImplCharts();
lista = dao.listar();
graficar(lista);
} catch (Exception e) {
System.out.println("Erro: "+e);
} finally {
}
}
private void graficar(List<Changes> lista) {
pieModel = new PieChartModel();
for (Changes chg : lista) {
pieModel.set(chg.getStatus(), chg.getId());
}
pieModel.setTitle("Status");
pieModel.setLegendPosition("e");
}
DAO
public class ChangesDaoImplCharts {
public List<Changes> listar() {
List<Changes> lista = null;
ResultSet rs;
Connection cn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testebd?user=root&password=root");
PreparedStatement st = cn.prepareStatement("SELECT * FROM changes");
rs = st.executeQuery();
lista = new ArrayList();
while (rs.next()) {
Changes chg = new Changes();
chg.setId(rs.getInt("id"));
chg.setStatus(rs.getString("status"));
lista.add(chg);
}
rs.close();
} catch (Exception e) {
System.out.println("Error: "+e);
} finally {
if (cn != null) {
try {
cn.close();
} catch (SQLException ex) {
Logger.getLogger(CustomerDaoImplCharts.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
return lista;
}
}