List of usage examples for org.jfree.chart JFreeChart createBufferedImage
public BufferedImage createBufferedImage(int width, int height, ChartRenderingInfo info)
From source file:de.bund.bfr.knime.pmm.common.chart.ChartUtilities.java
public static PNGImageContent convertToPNGImageContent(JFreeChart chart, int width, int height) { try {//from www.j av a 2s. c o m BufferedImage img; if (chart != null) { ChartRenderingInfo info = new ChartRenderingInfo(); img = chart.createBufferedImage(width, 5000, info); img = chart.createBufferedImage(width, (int) (img.getHeight() - info.getPlotInfo().getDataArea().getHeight() + height)); } else { img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); } return new PNGImageContent(org.jfree.chart.ChartUtilities.encodeAsPNG(img)); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:net.sf.jasperreports.charts.util.ChartUtil.java
/** * // w ww.j a va 2 s . c o m */ public static List<JRPrintImageAreaHyperlink> getImageAreaHyperlinks(JFreeChart chart, ChartHyperlinkProvider chartHyperlinkProvider, Graphics2D grx, Rectangle2D renderingArea)// throws JRException { List<JRPrintImageAreaHyperlink> areaHyperlinks = null; if (chartHyperlinkProvider != null && chartHyperlinkProvider.hasHyperlinks()) { ChartRenderingInfo renderingInfo = new ChartRenderingInfo(); if (grx == null) { chart.createBufferedImage((int) renderingArea.getWidth(), (int) renderingArea.getHeight(), renderingInfo); } else { chart.draw(grx, renderingArea, renderingInfo); } EntityCollection entityCollection = renderingInfo.getEntityCollection(); if (entityCollection != null && entityCollection.getEntityCount() > 0) { areaHyperlinks = new ArrayList<JRPrintImageAreaHyperlink>(entityCollection.getEntityCount()); for (@SuppressWarnings("unchecked") Iterator<ChartEntity> it = entityCollection.iterator(); it.hasNext();) { ChartEntity entity = it.next(); JRPrintHyperlink printHyperlink = chartHyperlinkProvider.getEntityHyperlink(entity); if (printHyperlink != null) { JRPrintImageArea area = getImageArea(entity); JRPrintImageAreaHyperlink areaHyperlink = new JRPrintImageAreaHyperlink(); areaHyperlink.setArea(area); areaHyperlink.setHyperlink(printHyperlink); areaHyperlinks.add(areaHyperlink); } } } } return areaHyperlinks; }
From source file:net.bioclipse.chart.ChartUtils.java
/** * Utility method for converting JFreeChart to an image * @param parent used for color correction * @param chart the chart to be made into an image * @param width image width// w w w .j av a 2 s .c o m * @param height image height * @return SWT Image of the chart */ public static Image createChartImage(Composite parent, JFreeChart chart, int width, int height) { // Color adjustment Color swtBackground = parent.getBackground(); java.awt.Color awtBackground = new java.awt.Color(swtBackground.getRed(), swtBackground.getGreen(), swtBackground.getRed()); chart.setBackgroundPaint(awtBackground); // Draw the chart in an AWT buffered image BufferedImage bufferedImage = chart.createBufferedImage(width, height, null); // Get the data buffer of the image DataBuffer buffer = bufferedImage.getRaster().getDataBuffer(); DataBufferInt intBuffer = (DataBufferInt) buffer; // Copy the data from the AWT buffer to a SWT buffer PaletteData paletteData = new PaletteData(0x00FF0000, 0x0000FF00, 0x000000FF); ImageData imageData = new ImageData(width, height, 32, paletteData); for (int bank = 0; bank < intBuffer.getNumBanks(); bank++) { int[] bankData = intBuffer.getData(bank); imageData.setPixels(0, bank, bankData.length, bankData, 0); } // Create an SWT image return new Image(parent.getDisplay(), imageData); }
From source file:com.greenpepper.confluence.macros.historic.AbstractChartBuilder.java
protected BufferedImage createChartImage(JFreeChart chart) { return chart.createBufferedImage(settings.getWidth(), settings.getHeight(), chartRenderingInfo); }
From source file:org.efs.openreports.engine.ChartReportEngine.java
private static ChartEngineOutput createChartOutput(ReportChart reportChart, ChartValue[] values) { JFreeChart chart = null; switch (reportChart.getChartType()) { case ReportChart.BAR_CHART: chart = createBarChart(reportChart, values); break;//w w w . j a v a 2 s . co m case ReportChart.PIE_CHART: chart = createPieChart(reportChart, values); break; case ReportChart.XY_CHART: chart = createXYChart(reportChart, values); break; case ReportChart.TIME_CHART: chart = createTimeChart(reportChart, values); break; case ReportChart.RING_CHART: chart = createRingChart(reportChart, values); break; } if (chart == null) return null; chart.setBackgroundPaint(Color.WHITE); ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); BufferedImage bufferedImage = chart.createBufferedImage(reportChart.getWidth(), reportChart.getHeight(), info); byte[] image = null; try { image = EncoderUtil.encode(bufferedImage, ImageFormat.JPEG); } catch (IOException ioe) { log.warn(ioe); } ChartEngineOutput chartOutput = new ChartEngineOutput(); chartOutput.setContent(image); chartOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_JPEG); chartOutput.setChartRenderingInfo(info); chartOutput.setChartValues(values); return chartOutput; }
From source file:org.inbio.ait.web.controller.ChartController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { JFreeChart chart = (JFreeChart) request.getSession(true).getAttribute("chart"); if (chart != null) { request.getSession(true).removeAttribute("chart"); //Set the content type response.setContentType("image/png"); //Send the image BufferedImage buf = chart.createBufferedImage(680, 440, null); PngEncoder encoder = new PngEncoder(buf, false, 0, 9); response.getOutputStream().write(encoder.pngEncode()); }//from w ww .j a v a 2s .c om return null; }
From source file:org.robotbrains.data.cloud.timeseries.server.web.StandardDataWebServer.java
/** * Write out the chart as an HTTP resonse. * //from w w w . jav a 2 s . c o m * @param response * the HTTP response * @param chart * the chart to be written * * @throws IOException * something bad happened */ private void writeChartResponse(HttpResponse response, JFreeChart chart) throws IOException { BufferedImage chartImage = chart.createBufferedImage(560, 370, null); ImageIO.write(chartImage, "png", response.getOutputStream()); response.setContentType(CommonMimeTypes.MIME_TYPE_IMAGE_PNG); }
From source file:nextapp.echo.chart.webcontainer.sync.component.ChartDisplayPeer.java
private String getImageMap(Component comp) { StringBuffer sb = new StringBuffer(); ChartDisplay chartDisplay = (ChartDisplay) comp; Extent ewidth = (Extent) chartDisplay.getRenderProperty(ChartDisplay.PROPERTY_WIDTH); int width = ewidth != null ? ewidth.getValue() : ChartDisplayPeer.DEFAULT_WIDTH; Extent eheight = (Extent) chartDisplay.getRenderProperty(ChartDisplay.PROPERTY_HEIGHT); int height = ewidth != null ? eheight.getValue() : ChartDisplayPeer.DEFAULT_HEIGHT; JFreeChart chart = chartDisplay.getChart(); BufferedImage image;/*from ww w . j a v a2 s. c o m*/ ChartRenderingInfo info = new ChartRenderingInfo(); synchronized (chart) { image = chart.createBufferedImage(width, height, info); } EntityCollection coll = info.getEntityCollection(); // debug("About to show entities"); // for (int i = 0; i < coll.getEntityCount(); i++) { // debug("Entity: " + coll.getEntity(i).getShapeCoords()); // debug("Entity: " + coll.getEntity(i).getShapeType()); // debug("Entity: " + coll.getEntity(i).getToolTipText()); // } sb.append("["); for (int i = 0; i < coll.getEntityCount(); i++) { if (i > 0) { sb.append(", "); } sb.append("{ shapeType: '" + coll.getEntity(i).getShapeType() + "'"); sb.append(", shapeCoords: '" + coll.getEntity(i).getShapeCoords() + "'"); sb.append(", actionCommand: '" + chartDisplay.getActionCommands()[i] + "'"); sb.append(", toolTipText: '" + coll.getEntity(i).getToolTipText() + "'}"); } sb.append("]"); return sb.toString(); }
From source file:tp1.G_AdminStats.java
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus // TODO add your handling code here: Map<String, Integer> att = new HashMap<String, Integer>(); DefaultTableModel model = (DefaultTableModel) tab3.getModel(); model.setRowCount(0);//www .j ava 2 s .c om try { Class.forName("java.sql.DriverManager"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/projectbuy", "root", "null"); Statement stmt = (Statement) con.createStatement(); String query = "SELECT usr, count(DISTINCT Datee) FROM attendence GROUP BY usr;"; ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String a = rs.getString(1); String b = rs.getString(2); model.addRow(new Object[] { a, b }); att.put(a, Integer.parseInt(b)); } } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage()); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Map.Entry<String, Integer> entry : att.entrySet()) { dataset.addValue(entry.getValue(), "series1", entry.getKey()); } JFreeChart chart = ChartFactory.createBarChart("Attendence", "Admin Name", "Days Present", dataset, PlotOrientation.VERTICAL, false, true, false); try { BufferedImage chartImage = chart.createBufferedImage(800, 300, null); labelGraph.setIcon(new javax.swing.ImageIcon(chartImage)); } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:org.n52.server.sos.generator.Generator.java
protected String createAndSaveImage(DesignOptions options, JFreeChart chart, ChartRenderingInfo renderingInfo) throws Exception { int width = options.getWidth(); int height = options.getHeight(); BufferedImage image = chart.createBufferedImage(width, height, renderingInfo); Graphics2D chartGraphics = image.createGraphics(); chartGraphics.setColor(Color.white); chartGraphics.fillRect(0, 0, width, height); chart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height)); try {/*from w ww . j ava 2s. c om*/ return ServletUtilities.saveChartAsPNG(chart, width, height, renderingInfo, null); } catch (IOException e) { throw new Exception("Could not save PNG!", e); } }