按日期系列实施BarChart

时间:2016-05-27 10:13:14

标签: jsf jsf-2 primefaces jsf-2.2

我将这些数据存储到数据库中:

enter image description here

我想按日期将数据生成到Primefaces条形图中:

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);
            }

但我得到了这个结果:

enter image description here

正如你所看到我只有一天,但它应该是4,因为我有4天进入数据库表。 Wha是使用Primefaces条形图中的4个系列列生成4天的正确方法吗?

1 个答案:

答案 0 :(得分:1)

试试这段代码:

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);