List of usage examples for org.jfree.chart JFreeChart createBufferedImage
public BufferedImage createBufferedImage(int width, int height, int imageType, ChartRenderingInfo info)
From source file:org.adempiere.webui.apps.graph.WPerformanceIndicator.java
/** * Init Graph Display//from ww w .j a va2 s .c om * Kinamo (pelgrim) */ private void init() { JFreeChart chart = createChart(); chart.setBackgroundPaint(Color.WHITE); chart.setBorderVisible(true); chart.setBorderPaint(Color.LIGHT_GRAY); chart.setAntiAlias(true); BufferedImage bi = chart.createBufferedImage(200, 120, BufferedImage.TRANSLUCENT, null); try { byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Image myImage = new Image(); myImage.setContent(image); appendChild(myImage); } catch (Exception e) { // TODO: handle exception } invalidate(); }
From source file:org.adempiere.webui.editor.WChartEditor.java
private void render(JFreeChart chart) { ChartRenderingInfo info = new ChartRenderingInfo(); int width = 400; int height = chartModel.getWinHeight(); BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info); try {/*from ww w . j av a 2s . c o m*/ byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Imagemap myImage = new Imagemap(); Panel panel = getComponent(); myImage.setContent(image); if (panel.getPanelchildren() != null) { panel.getPanelchildren().getChildren().clear(); panel.getPanelchildren().appendChild(myImage); } else { Panelchildren pc = new Panelchildren(); panel.appendChild(pc); pc.appendChild(myImage); } int count = 0; for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) { ChartEntity entity = (ChartEntity) it.next(); String key = null; String seriesName = null; if (entity instanceof CategoryItemEntity) { CategoryItemEntity item = ((CategoryItemEntity) entity); Comparable<?> colKey = item.getColumnKey(); Comparable<?> rowKey = item.getRowKey(); if (colKey != null && rowKey != null) { key = colKey.toString(); seriesName = rowKey.toString(); } } else if (entity instanceof PieSectionEntity) { Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey(); if (sectionKey != null) { key = sectionKey.toString(); } } if (entity instanceof XYItemEntity) { XYItemEntity item = ((XYItemEntity) entity); if (item.getDataset() instanceof TimeSeriesCollection) { TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset(); TimeSeries series = data.getSeries(item.getSeriesIndex()); TimeSeriesDataItem dataitem = series.getDataItem(item.getItem()); seriesName = series.getKey().toString(); key = dataitem.getPeriod().toString(); } } if (key == null) continue; Area area = new Area(); myImage.appendChild(area); area.setCoords(entity.getShapeCoords()); area.setShape(entity.getShapeType()); area.setTooltiptext(entity.getToolTipText()); area.setId(count + "_WG__" + seriesName + "__" + key); count++; } myImage.addEventListener(Events.ON_CLICK, new EventListener() { public void onEvent(Event event) throws Exception { MouseEvent me = (MouseEvent) event; String areaId = me.getArea(); if (areaId != null) { String[] strs = areaId.split("__"); if (strs.length == 3) { chartMouseClicked(strs[2], strs[1]); } } } }); } catch (Exception e) { log.log(Level.SEVERE, "", e); } }
From source file:org.adempiere.webui.apps.graph.jfreegraph.ChartRendererServiceImpl.java
@Override public boolean renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, final GoalModel goalModel) { GraphBuilder builder = new GraphBuilder(); builder.setMGoal(goalModel.goal);// w ww. jav a 2 s . c o m builder.setXAxisLabel(goalModel.xAxisLabel); builder.setYAxisLabel(goalModel.yAxisLabel); builder.loadDataSet(goalModel.columnList); JFreeChart chart = builder.createChart(goalModel.chartType); ChartRenderingInfo info = new ChartRenderingInfo(); chart.getPlot().setForegroundAlpha(0.6f); if (goalModel.zoomFactor > 0) { chartWidth = chartWidth * goalModel.zoomFactor / 100; chartHeight = chartHeight * goalModel.zoomFactor / 100; } if (!goalModel.showTitle) { chart.setTitle(""); } BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, info); try { byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Imagemap myImage = new Imagemap(); myImage.setContent(image); parent.appendChild(myImage); int count = 0; for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) { ChartEntity entity = (ChartEntity) it.next(); String key = null; if (entity instanceof CategoryItemEntity) { Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey(); if (colKey != null) { key = colKey.toString(); } } else if (entity instanceof PieSectionEntity) { Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey(); if (sectionKey != null) { key = sectionKey.toString(); } } if (key == null) { continue; } Area area = new Area(); myImage.appendChild(area); area.setCoords(entity.getShapeCoords()); area.setShape(entity.getShapeType()); area.setTooltiptext(entity.getToolTipText()); area.setId(count + "_WG_" + key); count++; } myImage.addEventListener(Events.ON_CLICK, new EventListener<Event>() { public void onEvent(Event event) throws Exception { MouseEvent me = (MouseEvent) event; String areaId = me.getArea(); if (areaId != null) { List<GraphColumn> list = goalModel.columnList; for (int i = 0; i < list.size(); i++) { String s = "_WG_" + list.get(i).getLabel(); if (areaId.endsWith(s)) { chartMouseClicked(goalModel.goal, list.get(i)); return; } } } } }); } catch (Exception e) { log.log(Level.SEVERE, "", e); return false; } return true; }
From source file:org.deegree.test.gui.StressTestController.java
private void drawDiagram(HttpServletResponse response, int width, int height) throws IOException { int n = resultData.size(); double[] values = new double[n]; for (int i = 0; i < n; i++) values[i] = resultData.get(i).getTimeElapsed() / 1000.0; HistogramDataset dataset = new HistogramDataset(); dataset.addSeries(new Double(1.0), values, n); JFreeChart chart = ChartFactory.createHistogram("timeVSfreq", "time", "frequency", dataset, PlotOrientation.VERTICAL, true, true, true); ChartRenderingInfo info = new ChartRenderingInfo(); BufferedImage buf = chart.createBufferedImage(width, height, 1, info); response.setContentType("image/jpeg"); OutputStream out = response.getOutputStream(); ImageIO.write(buf, "jpg", out); out.close();/*ww w. j a v a 2 s . c om*/ }
From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java
/** * Create a box plot qimage./* ww w .ja v a 2s . com*/ * @param data Data to use * @return a QImage */ public QImage createBoxPlot(final double[] data, final String unit) { if (data == null || data.length < 2) return null; this.width = this.width / 2; List<Float> listData = new ArrayList<Float>(data.length); for (int i = 0; i < data.length; i++) listData.add((float) data[i]); DefaultBoxAndWhiskerCategoryDataset defaultboxandwhiskercategorydataset = new DefaultBoxAndWhiskerCategoryDataset(); defaultboxandwhiskercategorydataset.add(listData, "Distances", "Min"); JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Intensities Boxplot", "", "Distance" + unitLegend(unit), defaultboxandwhiskercategorydataset, false); addTransparency(chart); final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB, null); return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height, QImage.Format.Format_ARGB32); }
From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java
/** * Create a histogram of distance distribution. * @param results Result to use//from ww w. java 2s . com * @return a QImage of the graph */ public QImage createDistanceDistributionImage(final CorsenResult results, final int classes, final String unit) { HistogramDataset histogramdataset = new HistogramDataset(); createHistoDataSet(results.getMinDistances(), "Min distances", histogramdataset, classes); // createHistoDataSet(results.getMaxDistances(), "Max distances", // histogramdataset); JFreeChart chart = ChartFactory.createHistogram("Distribution of minimal distances", // title "Distance" + unitLegend(unit), // domain axis label "Intensity", // range axis label histogramdataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); addTransparency(chart); final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB, null); return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height, QImage.Format.Format_ARGB32); }
From source file:org.adempiere.webui.apps.graph.WGraph.java
private void render(JFreeChart chart) { ChartRenderingInfo info = new ChartRenderingInfo(); int width = 560; int height = 400; if (zoomFactor > 0) { width = width * zoomFactor / 100; height = height * zoomFactor / 100; }/*from w w w . j av a2s . c om*/ if (m_hideTitle) { chart.setTitle(""); } BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info); try { byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Imagemap myImage = new Imagemap(); myImage.setContent(image); if (panel.getPanelchildren() != null) { panel.getPanelchildren().getChildren().clear(); panel.getPanelchildren().appendChild(myImage); } else { Panelchildren pc = new Panelchildren(); panel.appendChild(pc); pc.appendChild(myImage); } int count = 0; for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) { ChartEntity entity = (ChartEntity) it.next(); String key = null; if (entity instanceof CategoryItemEntity) { Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey(); if (colKey != null) { key = colKey.toString(); } } else if (entity instanceof PieSectionEntity) { Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey(); if (sectionKey != null) { key = sectionKey.toString(); } } if (key == null) { continue; } Area area = new Area(); myImage.appendChild(area); area.setCoords(entity.getShapeCoords()); area.setShape(entity.getShapeType()); area.setTooltiptext(entity.getToolTipText()); area.setId(count + "_WG_" + key); count++; } myImage.addEventListener(Events.ON_CLICK, new EventListener() { public void onEvent(Event event) throws Exception { MouseEvent me = (MouseEvent) event; String areaId = me.getArea(); if (areaId != null) { for (int i = 0; i < list.size(); i++) { String s = "_WG_" + list.get(i).getLabel(); if (areaId.endsWith(s)) { chartMouseClicked(i); return; } } } } }); } catch (Exception e) { log.log(Level.SEVERE, "", e); } }
From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java
public QImage createDistanceDistributionImage(final double[] data, final int classes, final String unit) { if (data == null || data.length < 2) return null; HistogramDataset histogramdataset = new HistogramDataset(); histogramdataset.addSeries("Min distances", data, classes, getMin(data), getMax(data)); // createHistoDataSet(results.getMaxDistances(), "Max distances", // histogramdataset); JFreeChart chart = ChartFactory.createHistogram("Distribution of minimal distances", // title "Distance" + unitLegend(unit), // domain axis label "Cell number", // range axis label histogramdataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? );//from w w w . ja va 2 s .co m addTransparency(chart); final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB, null); return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height, QImage.Format.Format_ARGB32); }
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button PieChart. <br>//from w w w .ja va 2 s .com * * @param event * @throws IOException */ public void onClick$button_CustomerChart_PieChart(Event event) throws InterruptedException, IOException { // logger.debug(event.toString()); div_chartArea.getChildren().clear(); // get the customer ID for which we want show a chart long kunId = getCustomer().getId(); // get a list of data List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId); if (kunAmountList.size() > 0) { DefaultPieDataset pieDataset = new DefaultPieDataset(); for (ChartData chartData : kunAmountList) { Calendar calendar = new GregorianCalendar(); calendar.setTime(chartData.getChartKunInvoiceDate()); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); String key = String.valueOf(month) + "/" + String.valueOf(year); BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3); String amount = String.valueOf(bd.doubleValue()); // fill the data pieDataset.setValue(key + " " + amount, new Double(chartData.getChartKunInvoiceAmount().doubleValue())); } String title = "Monthly amount for year 2009"; JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, true, true, true); PiePlot plot = (PiePlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Pie Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(div_chartArea); } else { div_chartArea.getChildren().clear(); Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button Ring Chart. <br> * /*from www. ja va 2s . c o m*/ * @param event * @throws IOException */ public void onClick$button_CustomerChart_RingChart(Event event) throws InterruptedException, IOException { // logger.debug(event.toString()); div_chartArea.getChildren().clear(); // get the customer ID for which we want show a chart long kunId = getCustomer().getId(); // get a list of data List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId); if (kunAmountList.size() > 0) { DefaultPieDataset pieDataset = new DefaultPieDataset(); for (ChartData chartData : kunAmountList) { Calendar calendar = new GregorianCalendar(); calendar.setTime(chartData.getChartKunInvoiceDate()); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); String key = String.valueOf(month) + "/" + String.valueOf(year); BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3); String amount = String.valueOf(bd.doubleValue()); // fill the data pieDataset.setValue(key + " " + amount, new Double(chartData.getChartKunInvoiceAmount().doubleValue())); } String title = "Monthly amount for year 2009"; JFreeChart chart = ChartFactory.createRingChart(title, pieDataset, true, true, true); RingPlot plot = (RingPlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Ring Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(this.div_chartArea); } else { div_chartArea.getChildren().clear(); final Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }