Time for action – creating a Pie chart using the JFreeChart API
In this section, we will demonstrate how to create a Pie chart using the JFreeChart API and rendering it using the <p:graphicImage>
and StreamedContent
API.
- Create a Pie chart using the JFreeChart API and attach the PrimeFaces
StreamedContent
to a stream-generated chart image.import java.io.File; import java.io.FileInputStream; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.primefaces.model.DefaultStreamedContent; import org.primefaces.model.StreamedContent; public StreamedContent getJfreeChart() { StreamedContent content = null; try { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("PrimeFaces", 455); dataset.setValue("JSF", 380); dataset.setValue("jQuery", 202); dataset...