Charts in Seam
From the Seam Forums:
Using JFreeChart with Seam can be quite useful:
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.
}
}
In your JSF page:
<s:graphicImage value="#{chartprocesser.chart}" />
About this entry
You’re currently reading “Charts in Seam,” an entry on Elegando
- Published:
- 07.25.07 / 9am
- Category:
- JBoss Seam
Comments