如何在图表中处理null

时间:2015-10-22 07:41:37

标签: jsf primefaces

我有一个图表,根据输入不足,数据可能为空。当我没有任何数据时,如何使图表返回非错误状态?

我总是可以伪造一个值,但这似乎很奇怪。我尝试将linemodel设置为null,但这没有帮助。这应该在xhtml或java代码中处理吗?

我遇到的问题是

javax.servlet.ServletException
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:667)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.lang.NullPointerException
    org.primefaces.component.chart.renderer.LineRenderer.encodeData(LineRenderer.java:36)
    org.primefaces.component.chart.renderer.BasePlotRenderer.render(BasePlotRenderer.java:29)
    org.primefaces.component.chart.ChartRenderer.encodeScript(ChartRenderer.java:98)

linemodel的代码

@PostConstruct
    public void collectData() {

        lineModel = new LineChartModel();
        ELContext elContext = FacesContext.getCurrentInstance().getELContext();
        MovingAverage movingAverage = (MovingAverage) elContext.getELResolver().getValue(elContext, null, "movingAverage");
        movingAverage.fetchMovingAverageForInstrument();
        LineChartSeries series1 = new LineChartSeries();


        series1.setLabel("MA 16");


        List<MovingAverageAsset> listMAA16;

        List<MovingAverageAsset> listMAA = movingAverage.getListMAA();
        if (listMAA == null) {
            return;
        }

所有内容都是通过按钮

更新的
<p:chart id="myChart" type="line" model="#{movingAverageChart.lineModel}" style="height:300px;"/>


            <p:commandButton value="Update"
                actionListener="#{movingAverageChart.collectData()}"
                 update=":listForm"/>

0 个答案:

没有答案