List of usage examples for org.jfree.chart JFreeChart createBufferedImage
public BufferedImage createBufferedImage(int width, int height)
From source file:logica_controladores.controlador_estadistica.java
public static void grafica_reorden(JPanel panel_grafica_orden, Inventario inventario, JLabel lbLinea) { XYSeries serie_2 = null;/*from w ww. ja va 2 s. co m*/ XYDataset datos; JFreeChart linea; serie_2 = new XYSeries("graficas relacion gastos-reorden"); for (int i = 0; i < inventario.getGastos().size(); i++) { serie_2.add(inventario.getGastos().get(i).getReorden(), inventario.getGastos().get(i).getGastos()); } datos = new XYSeriesCollection(serie_2); linea = ChartFactory.createXYLineChart("grafica representativa de reordenes por corrida", "punto de orden", "gastos", datos, PlotOrientation.VERTICAL, true, true, true); BufferedImage graficoLinea = linea.createBufferedImage(panel_grafica_orden.getWidth(), panel_grafica_orden.getHeight()); lbLinea.setSize(panel_grafica_orden.getSize()); lbLinea.setIcon(new ImageIcon(graficoLinea)); panel_grafica_orden.updateUI(); }
From source file:weka.core.ChartUtils.java
/** * Create a box plot buffered image from summary data (mean, median, q1, q3, * min, max, minOutlier, maxOutlier, list of outliers) * /* w w w . j a v a 2 s. c o m*/ * @param width the width of the resulting image * @param height the height of the resulting image * @param summary summary data * @param outliers list of outlier values * @param additionalArgs additional options to the renderer * @return a box plot chart * @throws Exception if a problem occurs */ public static BufferedImage renderBoxPlotFromSummaryData(int width, int height, List<Double> summary, List<Double> outliers, List<String> additionalArgs) throws Exception { JFreeChart chart = getBoxPlotFromSummaryData(summary, outliers, additionalArgs); BufferedImage image = chart.createBufferedImage(width, height); return image; }
From source file:weka.core.ChartUtils.java
/** * Render a pie chart from summary data (i.e. a list of values and their * corresponding frequencies) to a buffered image * /* ww w . j a va 2 s.c o m*/ * @param width the width of the resulting image * @param height the height of the resulting image * @param values a list of values for the chart * @param freqs a list of corresponding frequencies * @param showLabels true if the chart will show labels * @param showLegend true if the chart will show a legend * @param additionalArgs optional arguments to the renderer (may be null) * @return a buffered image * @throws Exception if a problem occurs */ public static BufferedImage renderPieChartFromSummaryData(int width, int height, List<String> values, List<Double> freqs, boolean showLabels, boolean showLegend, List<String> additionalArgs) throws Exception { JFreeChart chart = getPieChartFromSummaryData(values, freqs, showLabels, showLegend, additionalArgs); BufferedImage image = chart.createBufferedImage(width, height); return image; }
From source file:de.bund.bfr.knime.chart.ChartUtils.java
public static ImagePortObject getImage(JFreeChart chart, boolean asSvg, int width, int height) { if (asSvg) {// w w w.j av a 2 s .c om SVGDocument document = (SVGDocument) new SVGDOMImplementation().createDocument(null, "svg", null); SVGGraphics2D g = new SVGGraphics2D(document); g.setSVGCanvasSize(new Dimension(width, height)); if (chart != null) { chart.draw(g, new Rectangle2D.Double(0, 0, width, height)); } g.dispose(); document.replaceChild(g.getRoot(), document.getDocumentElement()); return new ImagePortObject(new SvgImageContent(document), new ImagePortObjectSpec(SvgCell.TYPE)); } else { try { BufferedImage img = chart != null ? chart.createBufferedImage(width, height) : new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); return new ImagePortObject(new PNGImageContent(ChartUtilities.encodeAsPNG(img)), new ImagePortObjectSpec(PNGImageContent.TYPE)); } catch (IOException e) { e.printStackTrace(); return null; } } }
From source file:org.opennms.netmgt.charts.ChartUtils.java
/** * Helper method used to return a JFreeChart as a buffered Image. * * @param chartName a {@link java.lang.String} object. * @return a <code>BufferedImage</code> * @throws org.exolab.castor.xml.MarshalException if any. * @throws org.exolab.castor.xml.ValidationException if any. * @throws java.io.IOException if any.// w w w .j ava2 s . c om * @throws java.sql.SQLException if any. */ public static BufferedImage getChartAsBufferedImage(String chartName) throws MarshalException, ValidationException, IOException, SQLException { BarChart chartConfig = getBarChartConfigByName(chartName); JFreeChart chart = getBarChart(chartName); ImageSize imageSize = chartConfig.getImageSize(); int hzPixels; int vtPixels; if (imageSize == null) { hzPixels = 400; vtPixels = 400; } else { hzPixels = imageSize.getHzSize().getPixels(); vtPixels = imageSize.getVtSize().getPixels(); } return chart.createBufferedImage(hzPixels, vtPixels); }
From source file:org.opennms.netmgt.charts.ChartUtils.java
/** * Helper method that returns the JFreeChart as a PNG byte array. * * @param chartName a {@link java.lang.String} object. * @return a byte array//from w w w . j av a 2s . c om * @throws org.exolab.castor.xml.MarshalException if any. * @throws org.exolab.castor.xml.ValidationException if any. * @throws java.io.IOException if any. * @throws java.sql.SQLException if any. */ public static byte[] getBarChartAsPNGByteArray(String chartName) throws MarshalException, ValidationException, IOException, SQLException { BarChart chartConfig = getBarChartConfigByName(chartName); JFreeChart chart = getBarChart(chartName); ImageSize imageSize = chartConfig.getImageSize(); int hzPixels; int vtPixels; if (imageSize == null) { hzPixels = 400; vtPixels = 400; } else { hzPixels = imageSize.getHzSize().getPixels(); vtPixels = imageSize.getVtSize().getPixels(); } return ChartUtilities.encodeAsPNG(chart.createBufferedImage(hzPixels, vtPixels)); }
From source file:weka.core.ChartUtils.java
/** * Render a histogram chart from summary data (i.e. a list of bin labels and * corresponding frequencies) to a buffered image * //from ww w .jav a2s . co m * @param width the width of the resulting image * @param height the height of the resulting image * @param bins the list of bin labels * @param freqs the corresponding bin frequencies * @param additionalArgs optional arguments to the renderer (may be null) * @return a histogram as a buffered image * @throws Exception if a problem occurs */ public static BufferedImage renderHistogramFromSummaryData(int width, int height, List<String> bins, List<Double> freqs, List<String> additionalArgs) throws Exception { JFreeChart chart = getHistogramFromSummaryDataChart(bins, freqs, additionalArgs); CategoryAxis axis = chart.getCategoryPlot().getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); Font newFont = new Font("SansSerif", Font.PLAIN, 11); axis.setTickLabelFont(newFont); BufferedImage image = chart.createBufferedImage(width, height); return image; }
From source file:cl.apr.pdf.chart.BarChartAviso.java
public static BufferedImage crearBarchart(List<BarChartItem> barChartItems) { BufferedImage bi = null;// w w w . ja va2 s. c o m try { ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme()); //ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme()); /* Step - 1: Define the data for the bar chart */ DefaultCategoryDataset my_bar_chart_dataset = new DefaultCategoryDataset(); int i = 0; for (BarChartItem barChartItem : barChartItems) { if (barChartItem.getNombre().equals("-")) { my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", (++i) + ""); } else my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", barChartItem.getNombre()); } // my_bar_chart_dataset.addValue(34, "mes", "Ene"); // my_bar_chart_dataset.addValue(25, "mes", "Feb"); // my_bar_chart_dataset.addValue(22, "mes", "Mar"); // my_bar_chart_dataset.addValue(12, "mes", "Abr"); // my_bar_chart_dataset.addValue(40, "mes", "May"); // my_bar_chart_dataset.addValue(30, "mes", "jun"); // my_bar_chart_dataset.addValue(2, "mes", "Jul"); // my_bar_chart_dataset.addValue(15, "mes", "Ago"); /* Step -2:Define the JFreeChart object to create bar chart */ //JFreeChart chart=ChartFactory.createBarChart("Detalle de sus consumos","","MT3",my_bar_chart_dataset,PlotOrientation.VERTICAL,true,true,false); JFreeChart chart = ChartFactory.createBarChart("", "", "MT3", my_bar_chart_dataset, PlotOrientation.VERTICAL, true, true, false); //chart.setBackgroundPaint(Color.lightGray); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); CategoryItemRenderer renderer = new CustomRenderer(); renderer.setSeriesPaint(0, Color.DARK_GRAY); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); chart.setBorderVisible(false); chart.setBackgroundPaint(Color.white); chart.setBorderStroke(null); chart.getLegend().visible = false; /* Step -3: Write the output as PNG file with bar chart information */ int width = 480; /* Width of the image */ int height = 250; /* Height of the image */ bi = chart.createBufferedImage(width, height); /* File BarChart=new File("output_chart.png"); ChartUtilities.saveChartAsPNG(BarChart,BarChartObject,width,height); */ } catch (Exception i) { System.out.println(i); } return bi; }
From source file:de.aidger.view.utils.Charts.java
/** * Creates a 3D pie chart.//from www .j ava 2 s . co m * * @param title * the diagram title * @param dataset * the dataset. * @param width * the width of the chart as image * @param height * the height of the chart as image * * @return the 3D pie chart as image */ public static ImageIcon createPieChart3D(String title, PieDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false); Font titleFont = UIManager.getFont("TitledBorder.font"); chart.setBackgroundPaint(null); chart.getLegend().setBackgroundPaint(null); chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14)); chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor")); chart.setBorderPaint(null); chart.getLegend().setBorder(0, 0, 0, 0); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setForegroundAlpha(0.9f); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage(_("No data to display.")); plot.setLabelGenerator(null); plot.setInsets(new RectangleInsets(10, 1, 5, 1)); plot.setBackgroundPaint(null); plot.setOutlineVisible(false); plot.setDarkerSides(true); return new ImageIcon(chart.createBufferedImage(width, height)); }
From source file:zw.co.hitrac.tpg.web.chart.GeneralChart.java
@Override protected IResource getImageResource() { return new DynamicImageResource() { @Override//from w ww . ja v a 2 s . c om protected byte[] getImageData(IResource.Attributes atrbts) { JFreeChart chart = createData(); return toImageData(chart.createBufferedImage(width, height)); } }; }