Java tutorial
/** * PureInfo Quake * @(#)ShowChartAction.java 1.0 Sep 26, 2005 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.srm.reports.cmd; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.struts.action.ActionForward; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import com.pureinfo.ark.interaction.ActionBase; import com.pureinfo.dolphin.model.DolphinObject; import com.pureinfo.force.exception.PureException; import com.pureinfo.srm.SRMExceptionTypes; import com.pureinfo.srm.reports.ReportConfigHelper; import com.pureinfo.srm.reports.impl.PieChartBuilder; /** * <P> * Created on Sep 26, 2005 3:18:01 PM <BR> * Last modified on Sep 26, 2005 * </P> * * @author Freeman.Hu * @version 1.0, Sep 26, 2005 * @since Quake 1.0 */ public class CopyOfShowChartAction extends ActionBase { /** * @see com.pureinfo.ark.interaction.ActionBase#executeAction() */ public ActionForward executeAction() throws PureException { String sID = request.getRequiredParameter("reportId", ""); ReportDataBiulder db = ChartReportHelper.getChartDataBiulderById(sID); List l = db.getListDatas(); List newList = new ArrayList(l.size()); for (Iterator iter = l.iterator(); iter.hasNext();) { DolphinObject obj = (DolphinObject) iter.next(); DolphinObject newObj = new DolphinObject(); newObj.setProperty("name", obj.getProperty("NAME")); newObj.setProperty("value", obj.getProperty("VALUE")); newList.add(newObj); } int chartType = PieChartBuilder.TYPE_PERCENT; if ("number".equals(request.getParameter("type"))) { chartType = PieChartBuilder.TYPE_NUMBER; } PieChartBuilder pb = new PieChartBuilder(newList, chartType, db.getTitle()); JFreeChart chart = pb.buildChart(); String sFileName = ReportConfigHelper.makeImageFileName("png"); try { String sPath = ReportConfigHelper.getImageLocalPath(); File file = new File(sPath, sFileName); if (logger.isDebugEnabled()) { logger.debug("to save report chart as " + file.getAbsolutePath()); } ChartUtilities.saveChartAsPNG(file, chart, 1000, 1000); request.setAttribute("img", sFileName); } catch (IOException ex) { throw new PureException(SRMExceptionTypes.REPORT_SAVE_CHART, sFileName, ex); } return mapping.findForward("success"); } }