Charts in Seam

From the Seam Forums:

Using JFreeChart with Seam can be quite useful:

package example.chartprocesser;

public class ChartProcesserBean {

    EntityManager em; // Entity Manager to access the database

    byte[] chart; // chart image (.png) as a byte array

    public void createChart() {

        DefaultCategoryDataset ds = this.getData;

        JFreeChart chart = ChartFactory.createLineChart(
                "Category Label",
                "Axis Lable",

     	    this.chart = ChartUtilities.encodeAsPNG(chart.createBufferedImage(400, 400));
        } catch (IOException e){


    private DefaultCategoryDataset getData(){
        //get the data and put into DefaultCategoryDataset
        //Then return it.

In your JSF page:

<s:graphicImage value="#{chartprocesser.chart}" />


  1. Hi Elengado,

    When I copy your source code and deploy application it display error that couldn’t find library of jfreechart but when I remove @Name(“chartprocesser”) then it didn’t display error.

    Can you help me resolve it because I have copied jfreechart and jcommon into java classpath

  2. so, what’s the point of this article then? Just to show that you was able to render a jfreechart on Seam?!

    Congratulations dude!!!!

    ps: lehoa, do you have those two libraries on both EAR project and the WEB project?

  3. Yup, that’s the point. This is a quick reference to how I would do this again without having to sift through irrelevant documentation.

Comments are closed.