【问题标题】:Nothing is shown using Primefaces LineChart使用 Primefaces LineChart 没有显示任何内容
【发布时间】:2013-04-09 20:42:29
【问题描述】:

谁能给我一个有关如何使用 Primefaces 的详细示例?

我使用了http://www.primefaces.org/showcase/ui/lineChart.jsf给出的简单示例

但是我的浏览器中什么也没有出现。这是我的代码:

lineChart.xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primeface.org/ui">
<h:head>
</h:head>
<h:body>
<p:lineChart id="linear" value="#{ChartBean.linearModel}" legendPosition="e"  
 title="Linear Chart" minY="0" maxY="10" style="height:300px"/>  

<p:lineChart id="category" value="#{ChartBean.categoryModel}" legendPosition="e"  
 title="Category Chart" minY="0" maxY="200" style="height:300px;margin-top:20px"/>  
</h:body>
</html>

ChartBean.java

public class ChartBean implements Serializable {  

/**
 * 
 */
private static final long serialVersionUID = 1L;

private CartesianChartModel categoryModel;  

private CartesianChartModel linearModel;  

public ChartBean() {  
    createCategoryModel();  
    createLinearModel();  
}  

public CartesianChartModel getCategoryModel() {  
    return categoryModel;  
}  

public CartesianChartModel getLinearModel() {  
    return linearModel;  
}  

private void createCategoryModel() {  
    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);  
}  

private void createLinearModel() {  
    linearModel = new CartesianChartModel();  

    LineChartSeries series1 = new LineChartSeries();  
    series1.setLabel("Series 1");  

    series1.set(1, 2);  
    series1.set(2, 1);  
    series1.set(3, 3);  
    series1.set(4, 6);  
    series1.set(5, 8);  

    LineChartSeries series2 = new LineChartSeries();  
    series2.setLabel("Series 2");  
    series2.setMarkerStyle("diamond");  

    series2.set(1, 6);  
    series2.set(2, 3);  
    series2.set(3, 2);  
    series2.set(4, 7);  
    series2.set(5, 9);  

    linearModel.addSeries(series1);  
    linearModel.addSeries(series2);  
}  
}

我有什么想念的吗?

【问题讨论】:

  • 你必须使用 xmlns:p="primefaces.org/ui",而不是 xmlns:p="primeface.org/ui"
  • @RongNK OMG,你救了我的命,我已经调试了将近一天...:D
  • 不客气,我会以anwser的身份发帖:)

标签: jsf-2 primefaces


【解决方案1】:

您必须使用 xmlns:p="primefaces.org/ui";,而不是 xmlns:p="primeface.org/ui";

【讨论】:

    猜你喜欢
    • 2020-03-24
    • 2014-07-21
    • 2016-02-19
    • 2020-06-16
    • 2021-02-05
    • 2018-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多