List of usage examples for org.jfree.chart JFreeChart createBufferedImage
public BufferedImage createBufferedImage(int width, int height, int imageType, ChartRenderingInfo info)
From source file:jgnash.ui.budget.BudgetSparkline.java
public static Icon getSparklineImage(final List<BigDecimal> amounts) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final boolean[] negate = new boolean[amounts.size()]; for (int i = 0; i < amounts.size(); i++) { dataset.addValue(amounts.get(i), CATEGORY, i); negate[i] = amounts.get(i).signum() == -1; }/*from w w w. j av a2 s .com*/ CategoryAxis xAxis = new CategoryAxis(); xAxis.setTickLabelsVisible(false); xAxis.setTickMarksVisible(false); xAxis.setAxisLineVisible(false); xAxis.setVisible(false); NumberAxis yAxis = new NumberAxis(); yAxis.setTickLabelsVisible(false); yAxis.setTickMarksVisible(false); yAxis.setAxisLineVisible(false); yAxis.setNegativeArrowVisible(false); yAxis.setPositiveArrowVisible(false); yAxis.setAutoRangeIncludesZero(true); yAxis.setAutoRange(true); yAxis.setVisible(false); BarRenderer renderer = new BarRenderer() { @Override public Paint getItemPaint(final int row, final int column) { return negate[column] ? Color.RED : Color.BLACK; } }; renderer.setShadowVisible(false); renderer.setBarPainter(new StandardBarPainter()); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setInsets(INSETS); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setBackgroundPaint(CLEAR); JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBorderVisible(false); chart.setBackgroundPaint(CLEAR); Icon icon = EMPTY_ICON; try { byte[] image = ENCODER .encode(chart.createBufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.BITMASK, null)); icon = new ImageIcon(image); } catch (IOException ex) { Logger.getLogger(BudgetSparkline.class.getName()).log(Level.SEVERE, null, ex); } return icon; }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private static Image createTerminationCallsPieImage(List<CdrGraphBean> beans) { // Create a dataset DefaultPieDataset data = new DefaultPieDataset(); // Fill dataset with beans data for (CdrGraphBean terminationCall : beans) { data.setValue(terminationCall.getKey(), terminationCall.getCount()); }//w ww .ja va 2 s . co m // Create a chart with the dataset JFreeChart chart = ChartFactory.createPieChart(EMPTY_TITLE, data, true, true, true); chart.setBackgroundPaint(Color.lightGray); chart.getTitle().setPaint(Color.BLACK); PiePlot chartplot = (PiePlot) chart.getPlot(); chartplot.setCircular(true); chartplot.setLabelGenerator(new StandardPieSectionLabelGenerator(PIECHART_SECTIONLABEL_FORMAT)); // Create and return the image return chart.createBufferedImage(500, 220, BufferedImage.TYPE_INT_RGB, null); }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private static Image createExtensionsChartImage(List<CdrGraphBean> extensions, String xAxisLabel, String yAxisLabel) {/*from w w w .j a va2 s.co m*/ // Create a dataset... DefaultCategoryDataset data = new DefaultCategoryDataset(); // Fill dataset with beans data for (CdrGraphBean extension : extensions) { data.setValue(extension.getCount(), extension.getKey(), extension.getKey()); } // Create a chart with the dataset JFreeChart barChart = ChartFactory.createBarChart3D(EMPTY_TITLE, xAxisLabel, yAxisLabel, data, PlotOrientation.VERTICAL, true, true, true); barChart.setBackgroundPaint(Color.lightGray); barChart.getTitle().setPaint(Color.BLACK); CategoryPlot p = barChart.getCategoryPlot(); p.setRangeGridlinePaint(Color.red); // Create and return the image with the size specified in the XML design return barChart.createBufferedImage(500, 220, BufferedImage.TYPE_INT_RGB, null); }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private static Image createMinutesOutgoingCallsChartImage(List<CdrMinutesGraphBean> minutesOutgoingCalls, String xAxisLabel, String yAxisLabel) { // Create a dataset... DefaultCategoryDataset data = new DefaultCategoryDataset(); // Fill dataset with beans data for (CdrMinutesGraphBean minutesOutgoingCall : minutesOutgoingCalls) { data.setValue(minutesOutgoingCall.getMinutes() / 60000, minutesOutgoingCall.getExtension(), minutesOutgoingCall.getExtension()); }/*from w w w .j av a2 s.c om*/ // Create a chart with the dataset JFreeChart barChart = ChartFactory.createBarChart3D(EMPTY_TITLE, xAxisLabel, yAxisLabel, data, PlotOrientation.VERTICAL, true, true, true); barChart.setBackgroundPaint(Color.lightGray); barChart.getTitle().setPaint(Color.BLACK); CategoryPlot p = barChart.getCategoryPlot(); p.setRangeGridlinePaint(Color.red); // Create and return the image with the size specified in the XML design return barChart.createBufferedImage(500, 220, BufferedImage.TYPE_INT_RGB, null); }
From source file:org.sonar.server.charts.deprecated.BaseChart.java
protected BufferedImage getBufferedImage(JFreeChart chart) { return chart.createBufferedImage(getWidth(), getHeight(), Transparency.BITMASK, null); }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
/** * Writes a chart to an output stream in JPEG format. This method allows * you to pass in a {@link ChartRenderingInfo} object, to collect * information about the chart dimensions/entities. You will need this * info if you want to create an HTML image map. * * @param out the output stream (<code>null</code> not permitted). * @param chart the chart (<code>null</code> not permitted). * @param width the image width./* ww w . j a v a 2 s . c o m*/ * @param height the image height. * @param info the chart rendering info (<code>null</code> permitted). * @param shapeMap * * @throws IOException if there are any I/O errors. */ public static void writeChartAsJPEG(File file, JFreeChart chart, int width, int height, ChartRenderingInfo info, Rectangle2D imageArea, LinkedHashMap<AbstractMask, Color> maskList, LinkedHashMap<Shape, Color> shapeMap, LinkedHashMap<Rectangle2D, String> textContentMap) throws IOException { if (file == null) { throw new IllegalArgumentException("Null 'file' argument."); } if (chart == null) { throw new IllegalArgumentException("Null 'chart' argument."); } OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); BufferedImage image = chart.createBufferedImage(width, height, BufferedImage.TYPE_INT_RGB, info); Graphics2D g2 = image.createGraphics(); drawMasks(g2, imageArea, maskList, null, chart); drawShapes(g2, imageArea, shapeMap, chart); drawText(g2, imageArea, textContentMap, chart); g2.dispose(); try { EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out); } finally { out.close(); } }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
/** * Writes a chart to an output stream in PNG format. This method allows * you to pass in a {@link ChartRenderingInfo} object, to collect * information about the chart dimensions/entities. You will need this * info if you want to create an HTML image map. * * @param out the output stream (<code>null</code> not permitted). * @param chart the chart (<code>null</code> not permitted). * @param width the image width.//w ww. j a va 2 s . com * @param height the image height. * @param info carries back chart rendering info (<code>null</code> * permitted). * @param shapeMap * @param encodeAlpha encode alpha? * @param compression the PNG compression level (0-9). * * @throws IOException if there are any I/O errors. */ public static void writeChartAsPNG(File file, JFreeChart chart, int width, int height, ChartRenderingInfo info, Rectangle2D imageArea, LinkedHashMap<AbstractMask, Color> maskList, LinkedHashMap<Shape, Color> shapeMap, LinkedHashMap<Rectangle2D, String> textContentMap) throws IOException { if (file == null) { throw new IllegalArgumentException("Null 'file' argument."); } if (chart == null) { throw new IllegalArgumentException("Null 'chart' argument."); } OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); BufferedImage chartImage = chart.createBufferedImage(width, height, BufferedImage.TYPE_INT_ARGB, info); Graphics2D g2 = chartImage.createGraphics(); drawMasks(g2, imageArea, maskList, null, chart); drawShapes(g2, imageArea, shapeMap, chart); drawText(g2, imageArea, textContentMap, chart); g2.dispose(); try { ChartUtilities.writeBufferedImageAsPNG(out, chartImage); } finally { out.close(); } }
From source file:org.eevolution.form.WCRP.java
private void renderChart(JFreeChart jchart) { BufferedImage bi = jchart.createBufferedImage(700, 500, Transparency.TRANSLUCENT, null); try {// w w w . j a v a2 s .c o m byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); chartPanel.removeChild(chart); chart = new Image(); chart.setContent(image); chartPanel.appendChild(chart); chartPanel.setVisible(true); } catch (Exception e) { } }
From source file:org.adempiere.webui.apps.graph.jfreegraph.ChartRendererServiceImpl.java
@Override public boolean renderPerformanceIndicator(Component parent, int chartWidth, int chartHeight, IndicatorModel model) {/* ww w . j av a 2 s .co m*/ PerformanceGraphBuilder builder = new PerformanceGraphBuilder(); JFreeChart chart = builder.createIndicatorChart(model); chart.setBackgroundPaint(model.chartBackground); chart.setAntiAlias(true); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); try { byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Image myImage = new Image(); myImage.setContent(image); parent.appendChild(myImage); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:org.eevolution.form.WCRPDetail.java
private void renderChart(JFreeChart jchart) { BufferedImage bi = jchart.createBufferedImage(700, 500, Transparency.TRANSLUCENT, null); try {// w w w. j a va 2s . c o m byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); mainLayout.removeChild(west); chartPanel = new Hbox(); chart = new Image(); chart.setContent(image); chartPanel.appendChild(chart); west = new West(); west.appendChild(chartPanel); west.setSplittable(true); west.setSize("70%"); west.setAutoscroll(true); west.setOpen(true); mainLayout.appendChild(west); } catch (Exception e) { log.log(Level.SEVERE, "WCRP.init", e.getMessage()); } }