2014-03-03 22 views
0

Primefaces附带图表组件。我尝试使用Atmosphere/push框架通过push操作更新图表。如何将更新推送到Primefaces图表?

的XHTML:

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

</p:panel> 
<h:form> 
    <p:commandButton value="Update" actionListener="#{beanViz.update()}"></p:commandButton> 
</h:form> 
<p:socket onMessage="handleMessage" channel="/counter" /> 

在beanViz的代码来创建折线图:

int increment = 0; 
private CartesianChartModel categoryModel; 
public CartesianChartModel getCategoryModel() { 
    return categoryModel; 
} 

private void createCategoryModel() { 
    categoryModel = new CartesianChartModel(); 
    ChartSeries boys = new ChartSeries(); 
    boys.setLabel("Boys"); 
    boys.set("2004", 120 + increment); 
    boys.set("2005", 100); 
    boys.set("2006", 44); 
    boys.set("2007", 150); 
    boys.set("2008", 25); 
    categoryModel.addSeries(boys); 
} 

现在,同样的页面图表上一个命令触发的更新图表中每隔一秒的一个值:

public void update() { 
    for (int i = 0; i < 50; i = i+5) { 
     increment = increment + i; 
     createCategoryModel(); 
     PushContext pushContext = PushContextFactory.getDefault().getPushContext(); 
     pushContext.push("/counter", ""); 
     try { 
      Thread.sleep(1000); 
     } catch (InterruptedException ex) { 
      Logger.getLogger(BeanViz.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } 
} 

问题:它不会更新图表的值,因此我不确定这是否正确。任何帮助?

回答