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:
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", 2); model.set("Watch TV", 2); model.set("Sleep", 7);
There's more...
The title
attribute defines the title of a chart. By default, the title is positioned at the top of the chart.
Positioning the legend
By default, the chart
component does not show any legends for its slices. By specifying the legendPosition
attribute, the legend can be activated...