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);
}
}
}
問題:它不會更新圖表的值,因此我不確定這是否正確。任何幫助?