BufferedImage drawChart(JFreeChart chart, int w, int h) { BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D gr = bi.createGraphics(); try { chart.draw(gr, new Rectangle2D.Double(0, 0, w, h)); } finally { gr.dispose(); } return bi; }
/** * Draws the chart on a Java 2D graphics device (such as the screen or a * printer). This method is the focus of the entire JFreeChart library. * * @param g2 the graphics device. * @param area the area within which the chart should be drawn. * @param info records info about the drawing (null means collect no info). */ public void draw(Graphics2D g2, Rectangle2D area, ChartRenderingInfo info) { draw(g2, area, null, info); }
/** * Draws the chart on a Java 2D graphics device (such as the screen or a * printer). This method is the focus of the entire JFreeChart library. * * @param g2 the graphics device. * @param area the area within which the chart should be drawn. * @param info records info about the drawing (null means collect no info). */ public void draw(Graphics2D g2, Rectangle2D area, ChartRenderingInfo info) { draw(g2, area, null, info); }
public void render(Graphics2D grx, Rectangle2D rectangle) { if (chart != null) { chart.draw(grx, rectangle); } }
public void render(Graphics2D grx, Rectangle2D rectangle) { if (chart != null) { chart.draw(grx, rectangle); } }
/** * Draws the chart on a Java 2D graphics device (such as the screen or a * printer). * <P> * This method is the focus of the entire JFreeChart library. * * @param g2 the graphics device. * @param area the area within which the chart should be drawn. */ public void draw(Graphics2D g2, Rectangle2D area) { draw(g2, area, null, null); }
/** * Draws the chart on a Java 2D graphics device (such as the screen or a * printer). * <P> * This method is the focus of the entire JFreeChart library. * * @param g2 the graphics device. * @param area the area within which the chart should be drawn. */ @Override public void draw(Graphics2D g2, Rectangle2D area) { draw(g2, area, null, null); }
@Override public void render(Graphics2D graphics2D) { chart1.draw(graphics2D, new Rectangle2D.Float((float) 0, (float) 0, (float) (width / dotsPerPixel), (float) (height / dotsPerPixel)), renderingInfo); } });
@Override public void render(Graphics2D graphics2D) { chart1.draw(graphics2D, new Rectangle2D.Float((float) 0, (float) 0, (float) (width / dotsPerPixel), (float) (height / dotsPerPixel)), renderingInfo); } });
BufferedImage drawChart(JFreeChart chart, int w, int h) { BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D gr = bi.createGraphics(); try { chart.draw(gr, new Rectangle2D.Double(0, 0, w, h)); } finally { gr.dispose(); } return bi; }
protected static BufferedImage draw(JFreeChart chart, int width, int height) { BufferedImage img = new BufferedImage(width , height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = img.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, width, height)); g2.dispose(); return img; } }
/** * Creates and returns a buffered image into which the chart has been drawn. * * @param width the width. * @param height the height. * @param imageType the image type. * @param info carries back chart state information ({@code null} * permitted). * * @return A buffered image. */ public BufferedImage createBufferedImage(int width, int height, int imageType, ChartRenderingInfo info) { BufferedImage image = new BufferedImage(width, height, imageType); Graphics2D g2 = image.createGraphics(); draw(g2, new Rectangle2D.Double(0, 0, width, height), null, info); g2.dispose(); return image; }
/** * Updates the graph image displayed of this. * Image includes graph data, axis, and legend. */ public void updateImage() { if (!lock) { GraphicsManager.recycleGCCompatibleImage(img); img = GraphicsManager.getGCCompatibleImage(150, 100); chart.draw(img.createGraphics(), new Rectangle2D.Double(0, 0, 150, 100), null); ImageIcon icon = new ImageIcon(img); //ImageIcon icon = new ImageIcon(chart.createBufferedImage(150, 100, 150.0, 100.0, null)); this.setIcon(icon); } }
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 { return ServletUtilities.saveChartAsPNG(chart, width, height, renderingInfo, null); } catch (IOException e) { throw new Exception("Could not save PNG!", e); } }
private void saveEPS(JFreeChart chart) { File f = new File(config.getString("/ofx/dir[@type='image-eps']")+"/"+chartName+".eps"); try { EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); FileOutputStream out = new FileOutputStream(f); g2d.setupDocument(out, width, height); chart.draw(g2d, new Rectangle2D.Double(0,0,width, height)); g2d.finish(); out.close(); } catch (FileNotFoundException e) {logger.error("",e);} catch (IOException e) {logger.error("",e);} }
public synchronized void renderGraph(Graphics2D g2d) { Rectangle2D r = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); try { redraw(); } catch (Exception e) { } getChart().draw(g2d, r); }
public synchronized void renderGraph(Graphics2D g2d) { Rectangle2D r = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); try { redraw(); } catch (Exception e) { } getChart().draw(g2d, r); }
private BufferedImage createImage() { IoParameters parameters = getParameters(); int width = parameters.getWidth(); int height = parameters.getHeight(); BufferedImage chartImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D chartGraphics = chartImage.createGraphics(); chartGraphics.fillRect(0, 0, width, height); chartGraphics.setColor(Color.WHITE); jFreeChart.setTextAntiAlias(true); jFreeChart.setAntiAlias(true); if (jFreeChart.getLegend() != null) { jFreeChart.getLegend() .setFrame(BlockBorder.NONE); } jFreeChart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height)); return chartImage; }
private BufferedImage drawChartToImage() { int width = getChartStyleDefinitions().getWidth(); int height = getChartStyleDefinitions().getHeight(); BufferedImage chartImage = new BufferedImage(width, height, TYPE_INT_RGB); Graphics2D chartGraphics = chartImage.createGraphics(); chartGraphics.fillRect(0, 0, width, height); chartGraphics.setColor(WHITE); chart.setTextAntiAlias(true); chart.setAntiAlias(true); if (chart.getLegend() != null) { chart.getLegend() .setFrame(BlockBorder.NONE); } chart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height)); return chartImage; }
public static void saveChartAsPDF(OutputStream out, JFreeChart chart, int width, int height) throws DocumentException { Rectangle pagesize = new Rectangle(width, height); Document document = new Document(pagesize, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, out); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height); chart.draw(g2, r2D); g2.dispose(); cb.addTemplate(tp, 0, 0); document.close(); }