O'Reilly logo

PrimeFaces Cookbook by Mert Çalışkan, Oleg Varaksin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Updating live data in charts with polling

It's possible to update the chart in a timely manner with the help of the <p:poll> component.

How to do it...

The following definition updates the pie chart every 3 seconds:

<p:poll interval="3" update="live" />
<p:pieChart id="live" value="#{pieChartController.livePieModel}" style="height:250px" />

The data model definition with the getter method, which will randomly create chart data, is given as follows:

PieChartModel liveChartModel = new PieChartModel(); liveChartModel.set("Candidate 1", 500); liveChartModel.set("Candidate 2", 300); public PieChartModel getLivePieModel() { int random1 = (int)(Math.random() * 1000); int random2 = (int)(Math.random() * 1000); liveChartModel.getData().put("Candidate 1", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required