Creating a Pie chart
The Pie chart component renders the category data as a Pie chart. The Pie chart uses the org.primefaces.model.chart.PieChartModel
type instance as a backing bean model.
Let us see how we can create a Pie chart representing the percentage of posts being created with various tags:
<p:pieChart value="#{chartController.pieChartModel}" style="width: 350px; height: 250px;" showDataLabels="true" legendPosition="ne"/> public class ChartController { private PieChartModel pieChartModel; public ChartController() { pieChartModel = new PieChartModel(); pieChartModel.set("JSF", 380); pieChartModel.set("PrimeFaces", 455); pieChartModel.set("jQuery", 202); pieChartModel.set("JPA", 180); } public PieChartModel getPieChartModel() { return pieChartModel; } }
The preceding code renders a Pie chart as follows:
In addition to the title
, legendPosition
, seriesColors...