java - 如何将更新推送到 Primefaces 图表?

标签 java primefaces charts atmosphere

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

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

问题:它没有按应有的方式更新图表的值,而且我完全不确定这是否是正确的处理方法。有什么帮助吗?

最佳答案

最近在 primefaces 展示中实现 http://www.primefaces.org/showcase-labs/push/chart.jsf

关于java - 如何将更新推送到 Primefaces 图表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22151322/

相关文章:

java - 在外部提供一个 for 循环的变量。这怎么可能?

java - 在 Ubuntu 中设置 Java 变量

primefaces - 重置 p :tree selected values

javascript - 如何在 WebGL 中提供 x 轴和 y 轴值?

project-management - 你用什么工具做燃尽图?

java - 严重: Allocate exception for servlet myServletName

java - 如何修复 java.lang.UnsupportedClassVersionError : Unsupported major. 次要版本

java - Primefaces p :fileDownload with datatable

jsf - h 的值 :inputText inside ui:repeat are not processed

javascript - 当键入 ="category"时,XAxis 在 Rechart 的散点图中重复自身