【问题标题】:Primefaces barChart not displaying when empty data from database当数据库中的数据为空时,Primefaces barChart 不显示
【发布时间】:2016-04-21 15:29:39
【问题描述】:

我正在使用从数据库中获取数据的 primefaces barChart,一切正常,除非没有来自数据库的数据,它会导致一个空白和被阻止的页面,当我打开 chrome 控制台时,javascript 错误说“未捕获的错误:没有指定数据”,那么我该如何处理这种情况以在没有指定数据时正确显示条形图

【问题讨论】:

  • 我想我遇到了同样的问题 - 我制作了一个 outputText(“未找到数据”或其他内容),在这种情况下将被渲染
  • @JaqenH'ghar 如何知道图表是否为空?
  • 我目前无法测试,但如果你根本不将系列添加到条形图中,如果没有数据,我猜你可以像

标签: primefaces jsf-2.2


【解决方案1】:

如果你想渲染图表,你可以用“空”数据填充它:

horizontalBarModel = new HorizontalBarChartModel();
 ChartSeries series = new ChartSeries();
    series.setLabel("seriesLabel");
    series.set("1", 0);
horizontalBarModel.addSeries(series);

如果您只是不想在没有数据的情况下渲染图表,那么在模型中添加一个布尔值并在填充数据时将其设置为 true/false 可能是一个不错的选择:

<p:chart type="bar" model="#{horizontalBarModel}" rendered="#{!emptyChart}"/> 

【讨论】:

    猜你喜欢
    • 2014-03-20
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 1970-01-01
    相关资源
    最近更新 更多