使用Primefaces LineChart没有显示任何内容

时间:2013-04-09 20:42:30

标签: jsf-2 primefaces

有人能给我一个关于如何使用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);  
}  
}

我会错过什么吗?

1 个答案:

答案 0 :(得分:1)

你必须使用xmlns:p =“primefaces.org/ui”;,而不是xmlns:p =“primeface.org/ui”;