gpt4 book ai didi

java - PrimeFaces barChart 未显示

转载 作者:行者123 更新时间:2023-12-01 13:23:55 25 4
gpt4 key购买 nike

我在使用条形图时遇到问题。我为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com