Question

I'm trying to make a simple line chart following the Primefaces showcase example, but with no success. The xhtml page is rendering an empty div. I've changed the bean scope and still not working. Here is my code:

@Named(value = "chartBean")
@RequestScoped
public class ChartBean {

    private CartesianChartModel categoryModel;

    public ChartBean() {  
        createCategoryModel(); 
    }  

    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);  
    }  

    public CartesianChartModel getCategoryModel() {
        return categoryModel;
    }

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

And my xhtml file:

<p:lineChart id="linear" value="#{chartBean.categoryModel}" legendPosition="e"  
                             title="Linear Chart" minY="0" maxY="10" style="height:300px">
 </p:lineChart>

I was using a facelets model client and now testing a simple xhtml file it works. But I need to use the client and the chart still not appearing on it. Any suggest?

Was it helpful?

Solution 3

I have solved the issue. I was using a script to fadeIn the page after it loads and was having a conflict with Primefaces rendering. I removed the display:none property and solved the question!

OTHER TIPS

I had the same problem then I wrapped the p:linechart with the p:panel and it worked!

Like this:

<p:panel header="Header">  
    <p:lineChart id="linear" value="#{chartBean.categoryModel}" legendPosition="e"  
        title="Linear Chart" minY="0" maxY="10" style="height:300px"/>
</p:panel>

Have you tried chartBean with view scope ??? Try with this....

@ManagedBean
@ViewScoped
public class ChartBean implements Serializable
{
     private static final long serialVersionUID = 1L
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top