List of usage examples for org.jfree.chart ChartUtilities saveChartAsPNG
public static void saveChartAsPNG(File file, JFreeChart chart, int width, int height) throws IOException
From source file:adept.utilities.Grapher.java
/** * Make time vs size graph./*from w w w.j a va 2 s. c om*/ * * @param timevalues the timevalues * @param sizevalues the sizevalues * @param filename the filename * @param linelabel the linelabel * @param Xlabel the xlabel * @param Ylabel the ylabel * @param title the title */ public static void makeTimeVsSizeGraph(ArrayList<Double> timevalues, ArrayList<Double> sizevalues, File filename, String linelabel, String Xlabel, String Ylabel, String title) { try { XYSeriesCollection scatter_plot_dataset = new XYSeriesCollection(); XYSeries data = new XYSeries(linelabel); for (int i = 0; i < sizevalues.size(); i++) { data.add(sizevalues.get(i), timevalues.get(i)); } scatter_plot_dataset.addSeries(data); /* Step -2:Define the JFreeChart object to create line chart */ JFreeChart scatterPlotObject = ChartFactory.createScatterPlot(Ylabel, Xlabel, title, scatter_plot_dataset, PlotOrientation.VERTICAL, true, true, false); /* Step -3 : Write line chart to a file */ int width = 640; /* Width of the image */ int height = 480; /* Height of the image */ ChartUtilities.saveChartAsPNG(filename, scatterPlotObject, width, height); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.pureinfo.srm.reports.cmd.CopyOfShowChartAction.java
/** * @see com.pureinfo.ark.interaction.ActionBase#executeAction() *///from ww w.ja v a 2 s.com 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"); }
From source file:com.pureinfo.srm.reports.cmd.ShowChartAction.java
/** * @see com.pureinfo.ark.interaction.ActionBase#executeAction() *///from w w w . j a v a2 s .co m public ActionForward executeAction() throws PureException { String sID = request.getRequiredParameter("reportId", ""); ReportDataBiulder db = ChartReportHelper.getChartDataBiulderById(sID); List l = db.getListDatas(); String msg = db.getMsg(); request.setAttribute("msg", msg); 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, 600, 600); request.setAttribute("img", sFileName); } catch (IOException ex) { throw new PureException(SRMExceptionTypes.REPORT_SAVE_CHART, sFileName, ex); } return mapping.findForward("success"); }
From source file:flusim.XY_Plotter.java
/** * Creates a chart./*from w w w .j a v a 2 s. c o m*/ * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset, String title) { JFreeChart chart = ChartFactory.createXYLineChart(title, // Title "Seconds Post Infection", // x-axis Label "Count", // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); try { ChartUtilities.saveChartAsPNG(new File(title + "-" + getDateTime() + ".png"), chart, 800, 640); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } chart.setBackgroundPaint(Color.white); return chart; }
From source file:e3fraud.gui.GraphingTool.java
public static void saveToFile(File file, JFreeChart lineChartObject) throws IOException { int width = 1024; /* Width of the image */ int height = 720; /* Height of the image */ ChartUtilities.saveChartAsPNG(file, lineChartObject, width, height); }
From source file:tr.gov.ptt.gr1tahsilatuyg.bean.TahsilatChartBean.java
public StreamedContent getJfreeChart() { StreamedContent content = null;/* w w w . ja va 2 s .com*/ try { chartListe = tahsilatBorcService.chartVerisiGetir(); for (Object[] chartElement : chartListe) { dataset.setValue(String.valueOf(chartElement[0]), Double.valueOf(chartElement[1].toString())); } boolean legend = true, tooltip = true, urls = false; JFreeChart chart = ChartFactory.createPieChart("JFreeChart", dataset, legend, tooltip, urls); File chartFile = new File("jfreechart"); int width = 375, height = 300; ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); content = new DefaultStreamedContent(new FileInputStream(chartFile), "image/png"); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } return content; }
From source file:com.pureinfo.srm.reports.action.ChartViewAction.java
/** * @throws PureException//from ww w .j av a 2s.c o m * @see com.pureinfo.ark.interaction.ActionBase#executeAction() */ public ActionForward executeAction() throws PureException { request.setAttribute("dept", "2"); ChartProvider provider = getProvider(); provider.setRequest(request.getHttpServletRequest()); Chart chartInfo = (Chart) request.getAttribute("chart"); if (chartInfo == null) { String sChartId = request.getParameter("id"); ChartContext context = new ChartContext(); context.setProvider(provider); context.setRequest(request.getHttpServletRequest()); chartInfo = provider.getChart(sChartId, context); } IChartBuilder builder = ChartBuildHelper.getChartBuilder(chartInfo); JFreeChart chart = builder.buildChart(); String sFileName = ReportConfigHelper.makeImageFileName("png"); ChartViewBean chartScale = builder.getChartViewBean(); request.setAttribute("chartScale", chartScale); request.setAttribute("filename", sFileName); try { String sPath = ReportConfigHelper.getImageLocalPath(); File file = new File(sPath, sFileName); ChartUtilities.saveChartAsPNG(file, chart, chartScale.getChartSize().x, chartScale.getChartSize().y); } catch (IOException ex) { ex.printStackTrace(); throw new PureException(SRMExceptionTypes.REPORT_SAVE_CHART, sFileName, ex); } if (chartScale.getLengedPosition() == ChartViewBean.LENGEND_POSITION_RIGHT) { return mapping.findForward("right-lengend"); } return mapping.findForward("bottom-lengend"); }
From source file:tr.gov.ptt.gr1tahsilatuyg.managedbean.ChartBean.java
public StreamedContent getJfreeChart() { StreamedContent content = null;/*from w w w . j a va 2 s.c om*/ try { chartListe = tahsilatBorcService.chartVerisiGetir(); for (Object[] chartElement : chartListe) { dataset.setValue(String.valueOf(chartElement[0]), Double.valueOf(chartElement[1].toString())); } boolean legend = true, tooltip = true, urls = false; JFreeChart chart = ChartFactory.createPieChart("JFreeChart", dataset, legend, tooltip, urls); File chartFile = new File("jfreechart"); int width = 375, height = 300; ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); content = new DefaultStreamedContent(new FileInputStream(chartFile), "image/png"); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } return content; }
From source file:gda.util.SavePNGPlot.java
/** * //from w w w . j a v a 2s .co m * @param imageFile * @param scan * @param width * @param height * @param chartTitle * @throws IOException */ public static void save(String imageFile, ScanFileHolder scan, int width, int height, String chartTitle) throws IOException { final XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series; IDataset x_axis = scan.getAxis(0); String[] headings = scan.getHeadings(); String yAxisName; if (headings.length == 2) yAxisName = headings[1]; else yAxisName = "various"; for (int seriesNum = 1; seriesNum < headings.length; seriesNum++) { series = new XYSeries(""); for (int point = 0, max = x_axis.getSize(); point < max - 1; point++) series.add(x_axis.getDouble(point), scan.getAxis(seriesNum).getDouble(point)); series.setKey(headings[seriesNum]); dataset.addSeries(series); } final JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart // title headings[0], // x axis label yAxisName, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend false, // tool tips false // url's ); ChartUtilities.saveChartAsPNG(new File(imageFile), chart, width, height); }
From source file:ntpgraphic.PieChart.java
public PieChart(String s) throws IOException { super(s);//from w w w . ja v a 2 s. c o m JPanel jpanel = createDemoPanel(); jpanel.setPreferredSize(new Dimension(500, 320)); setContentPane(jpanel); ChartUtilities.saveChartAsPNG(new File("/Users/JuanCa/Desktop/grafica_9.png"), jfreechart, 500, 300); }