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

Creating a pie chart

The pieChart component visualizes category data as a pie chart.

How to do it...

A simple definition for a pie chart with categories of data for displaying hours spent per day is shown as follows:

<p:pieChart value="#{pieChartController.model}" style="height:250px" title="Hours per Day" />

The chart will be rendered as follows:

How to do it...

The model that binds to the component should be an instance of org.primefaces.model.chart.PieChartModel. The definition of the model along with the categories is given in the following code snippet:

PieChartModel model = new PieChartModel(); model.set("Work", 11); model.set("Eat", 2); model.set("Commute", ...

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