Reputation: 1588
I have this data stored into database:
I would like to generate the data into Primefaces bar chart by date:
TicketStatusReportObj obj;
List<TicketStatusReportObj> list = new ArrayList<>();
...
// here we insert days using loop with data from database:
obj = new TicketStatusReportObj(
rs.getInt("CNT_STATUS0"),
rs.getInt("CNT_STATUS1"),
rs.getInt("CNT_STATUS2"),
rs.getInt("CNT_STATUS3"),
rs.getInt("CNT_STATUS4"),
rs.getDate("CREATED")
);
list.add(obj);
...
ChartSeries series;
for (int i = 0; i < list.size(); i++)
{
series = new ChartSeries();
TicketStatusReportObj get = list.get(i);
int in_progress = get.getIn_progress();
int new_ticket = get.getNew_ticket();
int closed = get.getClosed();
int resolved = get.getResolved();
int rejected = get.getRejected();
Date date = get.getDate();
series.setLabel(date.toString());
series.set(date.toString(), in_progress);
series.set(date.toString(), new_ticket);
series.set(date.toString(), closed);
series.set(date.toString(), resolved);
series.set(date.toString(), rejected);
barModel.addSeries(series);
}
But I get this result:
As you can see I have only one day but it shoud be 4 because I have 4 days into the database table. Wha is the proper way to generate 4 days with 4 series of columns in Primefaces Bar chart?
Upvotes: 0
Views: 113
Reputation: 661
Try this code:
ChartSeries series1 = new ChartSeries();
ChartSeries series2 = new ChartSeries();
ChartSeries series3 = new ChartSeries();
ChartSeries series4 = new ChartSeries();
ChartSeries series1 = new ChartSeries();
series1.setLabel("In Progress");
series2.setLabel("New Ticket");
series3.setLabel("Closed");
series4.setLabel("Resolved");
series5.setLabel("Rejected");
for (int i = 0; i < list.size(); i++)
{
TicketStatusReportObj get = list.get(i);
int in_progress = get.getIn_progress();
int new_ticket = get.getNew_ticket();
int closed = get.getClosed();
int resolved = get.getResolved();
int rejected = get.getRejected();
Date date = get.getDate();
series1.set(date, in_progress);
series2.set(date, new_ticket);
series3.set(date, closed);
series4.set(date, resolved);
series5.set(date, rejected);
}
barModel.addSeries(series1);
barModel.addSeries(series2);
barModel.addSeries(series3);
barModel.addSeries(series4);
barModel.addSeries(series5);
Upvotes: 1