I have a method that does a query in the database and returns me a List
, in this List
I have three data that interest me: Funcionário
and StatusTarefa
.
Example: I have 2 Employees performing various tasks, a task can have two statuses, Finalizado
and Pausado
. I would like to display in a graph the amount of Tasks Finished and Paused per employee. But I have a doubt, I believe that for this I would need to use an operation to group and count the statuses. How do I do this?
Image that exemplifies how I want to leave the chart:
I'mdoingthisgraphwithfixeddata:
@ManagedBean@RequestScopedpublicclassGraficoBarraBean{privateBarChartModelbarModel;publicvoidinit(){this.barModel=newBarChartModel();createBarModels();}publicBarChartModelgetBarModel(){returnbarModel;}privateBarChartModelinitBarModel(){BarChartModelmodel=newBarChartModel();ChartSeriesfinalizado=newChartSeries();finalizado.setLabel("Finalizado");
finalizado.set("Diego", 6);
finalizado.set("Lucas", 10);
finalizado.set("Cris", 12);
ChartSeries pausado = new ChartSeries();
pausado.setLabel("Pausado");
pausado.set("Diego", 2);
pausado.set("Lucas", 1);
pausado.set("Cris", 7);
model.addSeries(finalizado);
model.addSeries(pausado);
model.setAnimate(true);
return model;
}
private void createBarModels() {
createBarModel();
}
private void createBarModel() {
barModel = initBarModel();
barModel.setTitle("Tarefas");
barModel.setLegendPosition("ne");
Axis xAxis = barModel.getAxis(AxisType.X);
xAxis.setLabel("Funcionários");
Axis yAxis = barModel.getAxis(AxisType.Y);
yAxis.setLabel("Tarefas");
yAxis.setMin(0);
yAxis.setMax(20);
}
//Método que faz a consulta no banco e atribui os dados a uma lista de Tarefas
public List<Tarefa> listarTodos() {
List<Tarefa> lista = new ArrayList<>();
try {
TarefaDAO tarefaDAO = new TarefaDAO();
lista = tarefaDAO.listar();
} catch (RuntimeException e) {
FacesUtil.adicionarMsgErro("Erro ao listar tarefas: "
+ e.getMessage());
}
return lista;
}
}