List of usage examples for org.jfree.chart ChartUtilities writeChartAsPNG
public static void writeChartAsPNG(OutputStream out, JFreeChart chart, int width, int height, boolean encodeAlpha, int compression) throws IOException
From source file:org.apache.qpid.disttest.charting.writer.ChartWriter.java
public void writeChartToFileSystem(JFreeChart chart, ChartingDefinition chartDef) { OutputStream pngOutputStream = null; try {/*from w w w. jav a 2 s .com*/ File pngFile = new File(_chartDirectory, chartDef.getChartStemName() + ".png"); pngOutputStream = new BufferedOutputStream(new FileOutputStream(pngFile)); ChartUtilities.writeChartAsPNG(pngOutputStream, chart, 600, 400, true, 0); pngOutputStream.close(); _chartFilesToChartDef.put(pngFile, chartDef); LOGGER.info("Written {} chart", pngFile); } catch (IOException e) { throw new ChartingException("Failed to create chart", e); } finally { if (pngOutputStream != null) { try { pngOutputStream.close(); } catch (IOException e) { throw new ChartingException("Failed to create chart", e); } } } }
From source file:org.opentaps.common.reporting.ChartViewHandler.java
/** * Encode chart as image/png and send it to browser * * @param chartContext/*from w ww .j a v a2 s . c om*/ * @param response * @throws IOException */ protected void sendChart(Map<String, Object> chartContext, HttpServletResponse response) throws IOException { JFreeChart chartObject = (JFreeChart) chartContext.get("chartObject"); Integer width = (Integer) chartContext.get("width"); Integer height = (Integer) chartContext.get("height"); Boolean encodeAlpha = (Boolean) chartContext.get("alphaCompression"); Integer compressRatio = (Integer) chartContext.get("compressRatio"); if (chartObject != null && width.compareTo(0) > 0 && height.compareTo(0) > 0) { response.setContentType("image/png"); if (encodeAlpha != null || (compressRatio != null && compressRatio.intValue() >= 0 && compressRatio.intValue() <= 9)) { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chartObject, width, height, encodeAlpha.booleanValue(), compressRatio.intValue()); } else { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chartObject, width, height); } } }
From source file:eu.delving.ChartEngine.java
private void writePNG(OutputStream outputStream, JFreeChart chart) throws IOException { ChartUtilities.writeChartAsPNG(outputStream, chart, width, height, true, ImageWriteParam.MODE_DEFAULT); }
From source file:org.jrecruiter.web.CustomChartResult.java
/** * Executes the result. Writes the given chart as a PNG or JPG to the servlet output stream. * * @param invocation an encapsulation of the action execution state. * @throws Exception if an error occurs when creating or writing the chart to the servlet output stream. *//*w w w.ja v a 2 s . c o m*/ public void execute(ActionInvocation invocation) throws Exception { if (!chartSet) { // if our chart hasn't been set (by the testcase), we'll look it up in the value stack chart = (JFreeChart) invocation.getStack().findValue(value, JFreeChart.class); } if (chart == null) {// we need to have a chart object - if not, blow up throw new IllegalArgumentException("No JFreeChart object found on the stack with name " + value); } // make sure we have some value for the width and height if (height == null) { throw new IllegalArgumentException("No height parameter was given."); } if (width == null) { throw new IllegalArgumentException("No width parameter was given."); } // get a reference to the servlet output stream to write our chart image to OutputStream os = ServletActionContext.getResponse().getOutputStream(); try { // check the type to see what kind of output we have to produce if ("png".equalsIgnoreCase(type)) { ChartUtilities.writeChartAsPNG(os, chart, width, height, true, 0); } else if ("jpg".equalsIgnoreCase(type) || "jpeg".equalsIgnoreCase(type)) { ChartUtilities.writeChartAsJPEG(os, chart, width, height); } else { throw new IllegalArgumentException( type + " is not a supported render type (only JPG and PNG are)."); } } finally { if (os != null) os.flush(); } }
From source file:gsn.vsensor.ChartVirtualSensor.java
/** * Plots the chart and sends it in the form of ByteArrayOutputStream to * outside./*from ww w.j a v a 2 s. co m*/ * * @return Returns the byteArrayOutputStream. */ public synchronized ByteArrayOutputStream writePlot() { if (!changed) return byteArrayOutputStream; byteArrayOutputStream.reset(); try { ChartUtilities.writeChartAsPNG(byteArrayOutputStream, chart, width, height, false, 8); } catch (IOException e) { logger.warn(e.getMessage(), e); } return byteArrayOutputStream; }
From source file:org.opennms.netmgt.charts.ChartUtils.java
/** * Helper method that returns the JFreeChart to an output stream written in JPEG format. * * @param chartName a {@link java.lang.String} object. * @param out a {@link java.io.OutputStream} object. * @throws org.exolab.castor.xml.MarshalException if any. * @throws org.exolab.castor.xml.ValidationException if any. * @throws java.io.IOException if any.//from w w w. j a va 2 s . c o m * @throws java.sql.SQLException if any. */ public static void getBarChartPNG(String chartName, OutputStream out) throws MarshalException, ValidationException, IOException, SQLException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); BarChart chartConfig = getBarChartConfigByName(chartName); JFreeChart chart = getBarChart(chartName); if (chartConfig.getChartBackgroundColor() != null) { setChartBackgroundColor(chartConfig, chart); } if (chartConfig.getPlotBackgroundColor() != null) { setPlotBackgroundColor(chartConfig, chart); } ImageSize imageSize = chartConfig.getImageSize(); int hzPixels; int vtPixels; if (imageSize == null) { hzPixels = 400; vtPixels = 400; } else { hzPixels = imageSize.getHzSize().getPixels(); vtPixels = imageSize.getVtSize().getPixels(); } ChartUtilities.writeChartAsPNG(out, chart, hzPixels, vtPixels, false, 6); }