Rendering dynamic charts using the JFreeChart API
PrimeFaces internally uses the jqPlot library, which is based on jQuery, to generate charts using a canvas element. We can also create charts on the server side using the JFreeChart library (http://www.jfree.org/jfreechart/) and render the chart images using the PrimeFaces <p:graphicImage>
component.
To add the JFreeChart
jar file to the classpath, add the following maven dependency.
<dependency> <groupId>jfree</groupId> <artifactId>jfreechart</artifactId> <version>1.0.13</version> </dependency>
Let us see how we can create a Pie chart using the JFreeChart API and render it using the PrimeFaces <p:graphicImage>
.