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

hispeedsurfer do-not-reply at jboss.com
Mon Nov 12 04:18:48 EST 2007


Here is an example based on engelme idea that is working for me

import java.io.IOException;
  | import java.io.Serializable;
  | 
  | import org.jboss.seam.annotations.Name;
  | import org.jfree.chart.ChartFactory;
  | import org.jfree.chart.ChartUtilities;
  | import org.jfree.chart.JFreeChart;
  | import org.jfree.chart.plot.PiePlot;
  | import org.jfree.data.general.DefaultPieDataset;
  | 
  | 
  | @Name("chartprocesser")
  | public class ChartProcessor implements Serializable{
  |     /**
  | 	 * 
  | 	 */
  | 	private static final long serialVersionUID = 1L;
  | 	byte[] chart;
  | 
  |     
  |     public void createChart()
  |     {
  | 
  |          final DefaultPieDataset dataset = new DefaultPieDataset();
  |          dataset.setValue("One", new Double(43.2));
  |          dataset.setValue("Two", new Double(10.0));
  |          dataset.setValue("Three", new Double(27.5));
  |          dataset.setValue("Four", new Double(17.5));
  |          dataset.setValue("Five", new Double(11.0));
  |          dataset.setValue("Six", new Double(19.4));
  |          final JFreeChart chart = ChartFactory.createPieChart(
  |                  "Pie Chart Demo 2",  // chart title
  |                  dataset,             // dataset
  |                  true,                // include legend
  |                  true,
  |                  false
  |              );
  |          final PiePlot plot = (PiePlot) chart.getPlot();
  |          plot.setNoDataMessage("No data available");
  | 
  |        try{
  |             this.chart = ChartUtilities.encodeAsPNG(chart.createBufferedImage(400, 400));
  |        } catch (IOException e){
  |             e.printStackTrace();
  |        }
  | 
  |   }
  | 
  | 
  | 	public byte[] getChart() {
  | 		createChart();
  | 		return chart;
  | 	}
  | 
  | 
  | 	public void setChart(byte[] chart) {
  | 		this.chart = chart;
  | 	}
  | 
  | }

<a:form id="chartform">
  | 		            <a:outputPanel id="chart">
  | 						<s:graphicImage value="#{chartprocesser.chart}"/>
  | 			        </a:outputPanel>
  | 			    </a:form>



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

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



More information about the jboss-user mailing list