[jboss-user] [JBoss Seam] - Re: Charts

engelme do-not-reply at jboss.com
Tue Jul 24 21:39:46 EDT 2007


I use JFreeCharts. Here is an example of what i do. The code is a little rough but gives the general idea.


  | package example.chartprocesser;
  | 
  | @Name("chartprocesser")
  | public class ChartProcesserBean implements  {
  | 
  |     @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.
  |     }
  | }
  | 

Then in the display page.


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

Take a look at the <s:graphicImage/> tag and the JFree docs for more on creating charts.

If you put this in a SFSB then you might want to put something to clear the
 chart before the method is run again, especially if the chart can change between renderings.

I usually use this in a stateless bean that does all of the processing for the page to be rendered. Then once rendered, the SLSB is destroyed (I hope) when the page is refreshed the SLSB gets recreated and the chart is rendered anew. No messing with storing images to the disk.

Hope this makes sense.

Micheal

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4067255#4067255

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4067255



More information about the jboss-user mailing list