Using JFreeChart with Seam

Graphic statistics in Seam with JFreeChart.
[code lang="java"]
package example.chartprocesser;

@Name("chartprocesser")
public class ChartProcesserBean {

@In
EntityManager em; // Entity Manager to access the database

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

@Factory(value="chart")
public void createChart() {

DefaultCategoryDataset ds = this.getData;

JFreeChart chart = ChartFactory.createLineChart(
"TITLE",
"Category Label",
"Axis Lable",
ds,
PlotOrientation.HORIZONTAL,
false,
false,
false
);

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

}

private DefaultCategoryDataset getData(){
//get the data and put into DefaultCategoryDataset
//Then return it.
}
}
[/code]
In your JSF page:
[code lang="xml"]
<s:graphicImage value="#{chartprocesser.chart}" />
[/code]

Komentarze

Popularne posty z tego bloga

Set up JBoss AS 5.1.0 and Seam 2.2.0 in Ubuntu 9.04