java - PrimeFaces barChart 未显示

标签 java jsf jsf-2 primefaces xhtml

我在使用条形图时遇到问题。 我为 Primefaces 编写了一个 barCharts 示例,但在页面上它们不可见。

这里是 Bean 类:

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;

@ManagedBean
@ViewScoped

public class InvoiceStatisticsBean implements Serializable {
private CartesianChartModel categoryModel; 

public InvoiceStatisticsBean() {
    categoryModel = new CartesianChartModel();  

    ChartSeries boys = new ChartSeries();  
    boys.setLabel("Boys");  

    boys.set("2004", 120);  
    boys.set("2005", 100);  
    boys.set("2006", 44);  
    boys.set("2007", 150);  
    boys.set("2008", 25);  

    ChartSeries girls = new ChartSeries();  
    girls.setLabel("Girls");  

    girls.set("2004", 52);  
    girls.set("2005", 60);  
    girls.set("2006", 110);  
    girls.set("2007", 135);  
    girls.set("2008", 120);  

    categoryModel.addSeries(boys);  
    categoryModel.addSeries(girls); 
}

public CartesianChartModel getCategoryModel() {
    return categoryModel;
}

public void setCategoryModel(CartesianChartModel categoryModel) {
    this.categoryModel = categoryModel;
}
}

这是 .xhtml 文件:

    <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Invoice Statistics</title>
    </h:head>
    <h:body>
        <ui:composition template="/templates/layout.xhtml">
            <ui:define name="header">
                <h1>Invoice Statistics</h1>
            </ui:define>

        <ui:define name="content">
            <p>There should be a barChart</p>   
            <p:barChart id="horizontal" value="#{invoiceStatisticsBean.categoryModel}" legendPosition="se" style="height:300px" title="Horizontal Bar Chart" orientation="horizontal" min="0" max="200"/>  
            <p:outputPanel>test</p:outputPanel>
        </ui:define>
    </ui:composition>
</h:body>
</html>

抱歉编辑不当,但这是我的第一个问题。

因此,如果我随后启动 .xhtml 页面,则页面上会保留 barChart 的空间,但不会显示任何内容。

谁能帮我解决这个问题吗?

最佳答案

 <p:panel>
       <p:chart ......>
 </p:panel>

应该可以解决这个问题,p:panel

关于java - PrimeFaces barChart 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21889574/

相关文章:

jsf - 为什么我的 p :progressBar not displayed, 只有数字?

java - 如何创建带有复选框的 JSF 表?

ajax - JSF h :commandButton fires other command buttons within form?

java - 将 spring-boot 连接到 azure sql server 时出现问题

java - 一个声称在零之前开始的属性,在 -512!将其重置为零,并希望最好

java - 从十六进制值到字符串的转换

jsf - 使用点 <f :facet> instead of an attribute or a child component

jsf-2 - 使用处理程序处理 JSF 中构造函数抛出的异常

重新显示同一页面时 JSF 2 : ViewScoped Problem, bean 未持久化

java - 启动器不可执行