Primefaces <p:chart>无法正确显示

时间:2018-07-22 02:22:29

标签: jsf charts primefaces

我正在尝试根据this示例构建日期图表:

.xhtml:

<p:chart id="graficoVendasPorPeriodo" type="line" model="#{relatorioVendaMB.vendasPorPeriodo}"/>

.java:

private void constroiVendasPorPeriodo(Date dataInicio, Date dataFim) {
    List<Object[]> vendasPeriodo = ControleVenda.listarQtdeVendasPorPeriodo(dataInicio, dataFim);
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");

    vendasPorPeriodo = new LineChartModel();

    LineChartSeries lcs = new LineChartSeries();
    lcs.setLabel("Vendas Por Período");
    int max = 0;

    for (Object[] obj : vendasPeriodo) {
        int i = ((BigInteger) obj[1]).intValue();
        lcs.set(obj[0], i);

        if (i >= max) {
            max = i;
        }
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(dataFim);
    calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 1);
    dataFim = calendar.getTime();

    calendar.setTime(dataInicio);
    calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - 1);
    dataInicio = calendar.getTime();

    vendasPorPeriodo.addSeries(lcs);

    vendasPorPeriodo.setTitle("Vendas por período");
    vendasPorPeriodo.setZoom(true);

    Axis yAxis = vendasPorPeriodo.getAxis(AxisType.Y);
    yAxis.setLabel("Vendas");
    yAxis.setMax(max+10);
    yAxis.setMin(0);

    DateAxis xAxis = new DateAxis("Período");
    xAxis.setTickAngle(-50);
    xAxis.setMin(sdf.format(dataInicio));
    xAxis.setMax(sdf.format(dataFim));
    xAxis.setTickFormat("%#d-%m-%Y");

    System.out.println("Período: " + sdf.format(dataInicio) + ", " + sdf.format(dataFim));

    vendasPorPeriodo.getAxes().put(AxisType.X, xAxis);
}// this method is being called in the '@PostConstruct' method

listarQtdeVendasPorPeriodo(dataInicio, dataFim)方法返回一个List<Object[]>,其中每个“ Object []”数组在第一个位置包含一个String,在第二个位置包含一个int。

问题是,当我执行代码时,绝对没有显示任何内容,甚至没有空白图表或异常。有人可以指出我的错误并帮助我解决此问题吗?预先感谢

1 个答案:

答案 0 :(得分:1)

我认为问题是Primefaces使用您的日期格式的底层Jqplot不正确。查看此答案:jqplot: "this.proxy.getTime is not a function" / date input parser?