2
I have a method that makes a query in the bank and returns me a List
, in that List
I have three data that interest me: Funcionário
and StatusTarefa
.
Example: I have 2 Employees performing various tasks, one task can have two status, Finalizado
and Pausado
. I would like to display on a chart the number of Completed and Paused tasks per employee. But I have a question, I believe that for this I would need to use an operation to group and count the status. How I do this?
Image that exemplifies how I want to leave the chart:
I’m making this graph with fixed data:
@ManagedBean
@RequestScoped
public class GraficoBarraBean {
private BarChartModel barModel;
public void init() {
this.barModel = new BarChartModel();
createBarModels();
}
public BarChartModel getBarModel() {
return barModel;
}
private BarChartModel initBarModel() {
BarChartModel model = new BarChartModel();
ChartSeries finalizado = new ChartSeries();
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;
}
}
Oops. I did some tests and the map ta returning the right data, now I will try to put in the graph
– DiegoAugusto
For example in my graphic model I have to pass two parameters, the second I put
tarefasFinalizadas.get(f)
which is the quantity and in the first which is the name of the Official placedtarefa.getNome()
?– DiegoAugusto
This way so far:
finalizado.setLabel("Finalizado");
 finalizado.set("Diego", tarefasFinalizadas.get(f));
– DiegoAugusto
You can use the
f.getNome()
since f is your employee, if you dotarefa.getNome()
will come the name of the task.– Dener
Thanks a lot for the help, I managed to solve the problem. Now I will study a little more about Hashmap
– DiegoAugusto
Oops. Here’s a good article: Java Hashmap: Working with Key-value Lists
– Dener