List of usage examples for org.jfree.chart ChartUtilities writeChartAsPNG
public static void writeChartAsPNG(OutputStream out, JFreeChart chart, int width, int height) throws IOException
From source file:net.commerce.zocalo.freechart.ChartTest.java
public void testXYAreaStepChart() throws IOException { Minute now = new Minute(); TimePeriodValuesCollection aSeries = createBottomValues(now); TimePeriodValuesCollection bSeries = createTopValues(now); File jpgFile = newEmptyFile(".", "StepAreaChart.jpg"); File pngFile = newEmptyFile(".", "StepAreaChart.png"); assertFalse(jpgFile.exists());/*from w ww.java 2 s. co m*/ assertFalse(pngFile.exists()); OutputStream jpgStream = new FileOutputStream(jpgFile); OutputStream pngStream = new FileOutputStream(pngFile); JFreeChart chart = ChartGenerator.createCustomXYStepAreaChart(aSeries, bSeries); ChartUtilities.writeChartAsJPEG(jpgStream, chart, 500, 500); ChartUtilities.writeChartAsPNG(pngStream, chart, 500, 500); assertTrue(jpgFile.exists()); assertTrue(pngFile.exists()); jpgFile.delete(); pngFile.delete(); }
From source file:crossspectrumapp.CrossSpectrumApp.java
private void plotData(double[] frequency, double[] power, double[] phase, String title, String subTitleText1, String subTitleText2) throws WebUtilException { XYSeries asdSeries = new XYSeries("asd"); XYSeries phiSeries = new XYSeries("phase"); for (int i = 1; i < frequency.length; i++) { double f = frequency[i]; double pwr = power[i]; double phi = phase[i]; asdSeries.add(f, pwr);/*from w ww .j a va 2 s. c o m*/ phiSeries.add(f, phi); } XYSeriesCollection asdCollection = new XYSeriesCollection(); asdCollection.addSeries(asdSeries); XYSeriesCollection phiCollection = new XYSeriesCollection(); phiCollection.addSeries(phiSeries); // create the chart XYItemRenderer asdRenderer = new StandardXYItemRenderer(); LogAxis asdAxis = new LogAxis("ASD counts/ \u221AHz"); XYPlot asdSubplot = new XYPlot(asdCollection, null, asdAxis, asdRenderer); asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYItemRenderer phiRenderer = new StandardXYItemRenderer(); NumberAxis phiAxis = new NumberAxis("Phase degrees"); XYPlot phiSubplot = new XYPlot(phiCollection, null, phiAxis, phiRenderer); asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new LogAxis("Frequency (Hz)")); plot.setGap(10.0); // add the subplots... plot.add(asdSubplot, 2); plot.add(phiSubplot, 1); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); Title subTitle = new TextTitle(subTitleText1); chart.addSubtitle(subTitle); subTitle = new TextTitle(subTitleText2); chart.addSubtitle(subTitle); ChartPanel panel = new ChartPanel(chart, true, true, true, false, true); panel.setPreferredSize(new java.awt.Dimension(cscl.getOutX(), cscl.getOutY())); FileOutputStream fos = null; try { fos = new FileOutputStream(cscl.getOfileName()); ChartUtilities.writeChartAsPNG(fos, chart, cscl.getOutX(), cscl.getOutY()); fos.close(); fos = null; } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } finally { try { if (fos != null) { fos.close(); } } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } } }
From source file:edu.scripps.fl.curves.plot.CurvePlot.java
public void write(OutputStream outputStream) throws IOException { ChartUtilities.writeChartAsPNG(outputStream, chart, getWidth(), getHeight()); outputStream.close(); }
From source file:edu.scripps.fl.curves.plot.CurvePlot.java
public byte[] writeBytes() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); ChartUtilities.writeChartAsPNG(os, chart, getWidth(), getHeight()); os.close();//from w w w . j ava2 s. com return os.toByteArray(); }
From source file:com.jbombardier.reports.OldReportGenerator.java
private void render(String title, TimeSeriesCollection timeSeriesCollection, File file) { JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title "Time", // x-axislabel "Elapsed / ms", // y-axislabel timeSeriesCollection, // data true, // createlegend? true, // generatetooltips? false// generateURLs? );/* w ww. java 2 s .c o m*/ try { FileOutputStream fos = new FileOutputStream(file); Log.info("Rendered " + title + " to " + file.getAbsolutePath()); ChartUtilities.writeChartAsPNG(fos, chart, 640, 480); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.jbombardier.reports.ReportGenerator.java
private static void render(String title, TimeSeriesCollection timeSeriesCollection, File file) { JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title "Time", // x-axislabel "Elapsed / ms", // y-axislabel timeSeriesCollection, // data true, // createlegend? true, // generatetooltips? false// generateURLs? );/* ww w. j ava2 s . c o m*/ try { FileOutputStream fos = new FileOutputStream(file); Log.info("Rendered " + title + " to " + file.getAbsolutePath()); ChartUtilities.writeChartAsPNG(fos, chart, 640, 480); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.owasp.benchmark.score.report.Scatter.java
public void writeChartToFile(File f, int height, int width) throws IOException { FileOutputStream stream = new FileOutputStream(f); ChartUtilities.writeChartAsPNG(stream, chart, height, width); stream.close();//w ww.j av a 2s . com }
From source file:com.jd.survey.web.statistics.StatisticsController.java
/** * Controller that handles the chart generation for a question statistics * @param surveyDefinitionId//from ww w . jav a 2 s .c o m * @param pageOrder * @param questionOrder * @param recordCount * @param response */ @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/chart/{surveyDefinitionId}/{questionId}") public void generatePieChart(@PathVariable("surveyDefinitionId") Long surveyDefinitionId, @PathVariable("questionId") Long questionId, HttpServletResponse response) { try { response.setContentType("image/png"); long recordCount = surveyService.surveyStatistic_get(surveyDefinitionId).getSubmittedCount(); PieDataset pieDataSet = createDataset(questionId, recordCount); JFreeChart chart = createChart(pieDataSet, ""); ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 340, 200); response.getOutputStream().close(); } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:aula1.Aula1.java
public static void geraGrafico(double[] x, double[] y) { DefaultCategoryDataset data;//from ww w.j a v a 2 s . c o m data = new DefaultCategoryDataset(); int i = 0; String s = ""; for (double d : x) { s = String.valueOf(d); data.addValue(y[i], "f(x)", s); i++; } JFreeChart grafico = ChartFactory.createLineChart("Aula 3", "X", "Y", data); try { System.out.println("Gerando Grfico"); OutputStream arq = new FileOutputStream("Grafico2.png"); ChartUtilities.writeChartAsPNG(arq, grafico, 2000, 1500); arq.close(); System.out.println("Feito!"); } catch (IOException error) { System.out.println("Erro inesperado com arquivo: " + error.getMessage()); } }
From source file:ubic.gemma.core.analysis.preprocess.batcheffects.ComBat.java
private void writePlot(OutputStream os, XYSeries empirical, XYSeries theory) { // ChartFactory.setChartTheme( StandardChartTheme.createLegacyTheme() ); XYSeriesCollection xySeriesCollection = new XYSeriesCollection(); xySeriesCollection.addSeries(empirical); xySeriesCollection.addSeries(theory); JFreeChart chart = ChartFactory.createXYLineChart("", "Magnitude", "Density", xySeriesCollection, PlotOrientation.VERTICAL, false, false, false); chart.getXYPlot().setRangeGridlinesVisible(false); chart.getXYPlot().setDomainGridlinesVisible(false); XYItemRenderer renderer = chart.getXYPlot().getRenderer(); renderer.setBasePaint(Color.white); try {//from www . j a v a 2 s .co m int size = 500; ChartUtilities.writeChartAsPNG(os, chart, 500, size); os.close(); } catch (IOException e) { throw new RuntimeException(e); } }