O'Reilly logo

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

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

The chart component nicely integrates with the <p:poll> component to update itself with an ever-changing data model.

How to do it…

A basic definition for a chart with live data is given here:

<p:poll interval="2" update="live" />
<p:chart id="live" type="pie" model="#{chartBean.livePieModel}"
  style="height:250px" />

The randomly generated model for the chart is implemented here:

public PieChartModel getLivePieModel() { int random1 = (int)(Math.random() * 1000); int random2 = (int)(Math.random() * 1000); liveChartModel.getData().put("Candidate 1", random1); liveChartModel.getData().put("Candidate 2", random2); liveChartModel.setLegendPosition("w"); liveChartModel.setShowDataLabels(true); return liveChartModel; ...

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