/* * Created on 2003-9-9 * http://www.sentom.net * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package net.sentom.chart;
/** * @author sentom * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class WebChart { private DefaultPieDataset data = new DefaultPieDataset();
public void setValue (String key,double value) { data.setValue(key,value); }
public String generatePieChart (String title, HttpSession session, PrintWriter pw) { String filename = null; try { //创建chart对象 PiePlot plot = new PiePlot(data); plot.setInsets (new Insets(0, 5, 5, 5)); //在统计图片上建连结 plot.setURLGenerator (new StandardPieURLGenerator ("link.jsp","section")); plot.setToolTipGenerator (new StandardPieToolTipGenerator()); JFreeChart chart = new JFreeChart ("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint (java.awt.Color.white); //设置图片的背景色 Font font = new Font ("黑体",Font.CENTER_BASELINE,20); //设置图片标题的字体和大小 TextTitle _title = new TextTitle(title); _title.setFont(font); chart.setTitle(_title); //把生成的图片放到临时目录 ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); //500是图片长度, 300是图片高度 filename = ServletUtilities. saveChartAsPNG (chart, 500, 300, info, session); ChartUtilities.writeImageMap (pw, filename, info); pw.flush(); } catch (Exception e) { System.out.println ("Exception - " + e.toString()); e.printStackTrace (System.out); filename = "public_error_500x300.png"; } return filename; } }