List of usage examples for org.jfree.chart JFreeChart createBufferedImage
public BufferedImage createBufferedImage(int width, int height)
From source file:result.analysis.Chart.java
private void save_jpeg(JFreeChart chart) { BufferedImage objBufferedImage = chart.createBufferedImage(1200, 900); ByteArrayOutputStream bas = new ByteArrayOutputStream(); try {/*w ww . j a va 2 s.c o m*/ ImageIO.write(objBufferedImage, "png", bas); } catch (IOException e) { e.printStackTrace(); } byte[] byteArray = bas.toByteArray(); InputStream in = new ByteArrayInputStream(byteArray); BufferedImage image = null; try { image = ImageIO.read(in); } catch (IOException ex) { Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, null, ex); } File outputfile = new File("Analysis files\\" + chart.getTitle().toString() + ".png"); try { ImageIO.write(image, "png", outputfile); } catch (IOException ex) { Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.drools.planner.benchmark.core.statistic.bestscore.BestScoreProblemStatistic.java
protected void writeGraphStatistic() { NumberAxis xAxis = new NumberAxis("Time spend"); xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat()); NumberAxis yAxis = new NumberAxis("Score"); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); int seriesIndex = 0; for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) { BestScoreSingleStatistic singleStatistic = (BestScoreSingleStatistic) singleBenchmark .getSingleStatistic(problemStatisticType); XYSeries series = new XYSeries(singleBenchmark.getSolverBenchmark().getName()); for (BestScoreSingleStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpend = point.getTimeMillisSpend(); Score score = point.getScore(); Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score); if (scoreGraphValue != null) { series.add(timeMillisSpend, scoreGraphValue); }// www. j a va2s. co m } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); plot.setDataset(seriesIndex, seriesCollection); XYItemRenderer renderer; // No direct lines between 2 points renderer = new XYStepRenderer(); if (singleStatistic.getPointList().size() <= 1) { // Workaround for https://sourceforge.net/tracker/?func=detail&aid=3387330&group_id=15494&atid=115494 renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES); } plot.setRenderer(seriesIndex, renderer); seriesIndex++; } plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(problemBenchmark.getName() + " best score statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); graphStatisticFile = new File(problemBenchmark.getProblemReportDirectory(), problemBenchmark.getName() + "BestScoreStatistic.png"); OutputStream out = null; try { out = new FileOutputStream(graphStatisticFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e); } finally { IOUtils.closeQuietly(out); } }
From source file:org.drools.planner.benchmark.statistic.calculatecount.CalculateCountStatistic.java
private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) { XYSeriesCollection seriesCollection = new XYSeriesCollection(); for (Map.Entry<String, CalculateCountStatisticListener> listenerEntry : statisticListenerMap.entrySet()) { String configName = listenerEntry.getKey(); XYSeries series = new XYSeries(configName); List<CalculateCountStatisticPoint> statisticPointList = listenerEntry.getValue() .getStatisticPointList(); for (CalculateCountStatisticPoint statisticPoint : statisticPointList) { long timeMillisSpend = statisticPoint.getTimeMillisSpend(); long calculateCountPerSecond = statisticPoint.getCalculateCountPerSecond(); series.add(timeMillisSpend, calculateCountPerSecond); }//from w w w.java 2s. co m seriesCollection.addSeries(series); } NumberAxis xAxis = new NumberAxis("Time millis spend"); xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat()); NumberAxis yAxis = new NumberAxis("Calculate count per second"); yAxis.setAutoRangeIncludesZero(false); XYItemRenderer renderer = new XYLineAndShapeRenderer(); XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(baseName + " calculate count statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "CalculateCountStatistic.png"); OutputStream out = null; try { out = new FileOutputStream(graphStatisticFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e); } finally { IOUtils.closeQuietly(out); } return " <img src=\"" + graphStatisticFile.getName() + "\"/>\n"; }
From source file:org.drools.planner.benchmark.statistic.memoryuse.MemoryUseStatistic.java
private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) { XYSeriesCollection seriesCollection = new XYSeriesCollection(); for (Map.Entry<String, MemoryUseStatisticListener> listenerEntry : statisticListenerMap.entrySet()) { String configName = listenerEntry.getKey(); XYSeries usedSeries = new XYSeries(configName + " used"); XYSeries maxSeries = new XYSeries(configName + " max"); List<MemoryUseStatisticPoint> statisticPointList = listenerEntry.getValue().getStatisticPointList(); for (MemoryUseStatisticPoint statisticPoint : statisticPointList) { long timeMillisSpend = statisticPoint.getTimeMillisSpend(); MemoryUseMeasurement memoryUseMeasurement = statisticPoint.getMemoryUseMeasurement(); usedSeries.add(timeMillisSpend, memoryUseMeasurement.getUsedMemory()); maxSeries.add(timeMillisSpend, memoryUseMeasurement.getMaxMemory()); }//from ww w . java 2 s . c o m seriesCollection.addSeries(usedSeries); seriesCollection.addSeries(maxSeries); } NumberAxis xAxis = new NumberAxis("Time millis spend"); xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat()); NumberAxis yAxis = new NumberAxis("Memory"); yAxis.setAutoRangeIncludesZero(false); XYItemRenderer renderer = new XYAreaRenderer2(); XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(baseName + " memory use statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "MemoryUseStatistic.png"); OutputStream out = null; try { out = new FileOutputStream(graphStatisticFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e); } finally { IOUtils.closeQuietly(out); } return " <img src=\"" + graphStatisticFile.getName() + "\"/>\n"; }
From source file:br.com.OCTur.view.InfograficoController.java
private BufferedImage receitaMensal() { DefaultCategoryDataset dcdDados = new DefaultCategoryDataset(); Calendar inicio = Calendar.getInstance(); System.out.println(this.inicio); inicio.setTime(this.inicio); MAIOR = 0;//from w ww .j a v a 2 s .c o m while (inicio.getTime().before(fim)) { Calendar mes = Calendar.getInstance(); mes.setTime(inicio.getTime()); mes.add(Calendar.MONTH, 1); List<Reserva> reservas = new ReservaDAO().pegarPorHotelInicioFim(hotel, inicio.getTime(), mes.getTime()); double total = 0; for (Reserva reserva : reservas) { long dias = (reserva.getFim().getTime() - reserva.getInicio().getTime()) / 1000 / 60 / 60 / 24; if (dias <= 0) { dias = 1; } total += (reserva.getQuarto().getOrcamento().getPreco() * dias); } if (total > MAIOR) { MAIOR = total; this.mes = DateFormatter.toFullMonthName(inicio.getTime()); } dcdDados.addValue(total, "Receita", DateFormatter.toMonthName(inicio.getTime())); inicio.add(Calendar.MONTH, 1); } JFreeChart jFreeChart = ChartFactory.createBarChart("", "", "", dcdDados, PlotOrientation.VERTICAL, false, false, false); return jFreeChart.createBufferedImage(555, 170); }
From source file:pe.egcc.app.demo.Demo02.java
private void btnMostrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMostrarActionPerformed // Definiendo la fuente de datos DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Artculo 1", 40.55); data.setValue("Artculo 2", 81.23); data.setValue("Artculo 3", 61.54); // Creando el grfico JFreeChart chart = ChartFactory.createPieChart("Ejemplo de Grfico Tipo Pastel", // Ttulo del grfico data, // DataSet true, // Leyenda true, // ToolTips true);/*from w w w . ja v a 2s. co m*/ // Dibujando el grfico en un jPanel BufferedImage imagen = chart.createBufferedImage(panelGrafico.getWidth() - 2, panelGrafico.getHeight() - 2); panelGrafico.getGraphics().drawImage(imagen, 1, 1, null); }
From source file:br.com.OCTur.view.InfograficoController.java
private BufferedImage classificacaoHotel() { DefaultCategoryDataset dcdDados = new DefaultCategoryDataset(); for (EntidadeGrafico<Hotel> hotel : hoteis.subList(0, hoteis.size() > 4 ? 4 : hoteis.size())) { for (TipoQuarto tipoQuarto : new TipoQuartoDAO().pegarTodos()) { Orcamento orcamento = new OrcamentoDAO().pegarPorTipoQuartoHotel(tipoQuarto, hotel.getEntidade()); if (orcamento != null) { List<Reserva> reservas = new ReservaDAO().pegarPorOrcamentoInicioFim(orcamento, inicio, fim); double total = 0; for (Reserva reserva : reservas) { long dias = (reserva.getFim().getTime() - reserva.getInicio().getTime()) / 1000 / 60 / 60 / 24;//www . j a va 2s . co m if (dias <= 0) { dias = 1; } total += (reserva.getQuarto().getOrcamento().getPreco() * dias); } dcdDados.addValue(total * 100 / hotel.getValue(), tipoQuarto.toString(), hotel.toString()); } } } JFreeChart jFreeChart = ChartFactory.createStackedBarChart("", "", "", dcdDados, PlotOrientation.HORIZONTAL, true, false, false); return jFreeChart.createBufferedImage(365, 251); }
From source file:org.drools.planner.benchmark.statistic.BestScoreStatistic.java
private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) { XYSeriesCollection seriesCollection = new XYSeriesCollection(); for (Map.Entry<String, BestScoreStatisticListener> listenerEntry : bestScoreStatisticListenerMap .entrySet()) {//from ww w . j a v a2s .co m String configName = listenerEntry.getKey(); XYSeries configSeries = new XYSeries(configName); List<BestScoreStatisticPoint> statisticPointList = listenerEntry.getValue() .getBestScoreStatisticPointList(); for (BestScoreStatisticPoint statisticPoint : statisticPointList) { long timeMillisSpend = statisticPoint.getTimeMillisSpend(); Score score = statisticPoint.getScore(); Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score); if (scoreGraphValue != null) { configSeries.add(timeMillisSpend, scoreGraphValue); } } seriesCollection.addSeries(configSeries); } NumberAxis xAxis = new NumberAxis("Time millis spend"); xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat()); NumberAxis yAxis = new NumberAxis("Score"); yAxis.setAutoRangeIncludesZero(false); XYItemRenderer renderer = new XYStepRenderer(); XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(baseName + " best score statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "Statistic.png"); OutputStream out = null; try { out = new FileOutputStream(graphStatisticFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e); } finally { IOUtils.closeQuietly(out); } return " <img src=\"" + graphStatisticFile.getName() + "\"/>\n"; }
From source file:cmsc105_mp2.Plot.java
public void createGraph(Data d, float window, Double threshold) { XYSeries data = new XYSeries("data"); double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (double num : d.plots) { if (max < num) max = num;/*from w w w . jav a 2 s .c o m*/ if (min > num) min = num; } max += 3; min -= 3; ArrayList<XYSeries> xy = new ArrayList(); ArrayList<Integer> points = new ArrayList(); for (int j = (int) (window / 2); j < d.plots.length - (window / 2); j++) { data.add(j, d.plots[j]); System.out.println(points.size()); if (d.plots[j] > threshold) { points.add(j); } else { if (points.size() >= window) { System.out.println("MIN!"); XYSeries series = new XYSeries("trend"); for (int n : points) { series.add(n, max); } xy.add(series); } points = new ArrayList(); } } if (points.size() >= window) { XYSeries series = new XYSeries("trend"); for (int n : points) { series.add(n, max); } xy.add(series); } XYSeriesCollection my_data_series = new XYSeriesCollection(); my_data_series.addSeries(data); for (XYSeries x : xy) { my_data_series.addSeries(x); } XYSeries thresh = new XYSeries("threshold"); for (int j = 0; j < d.plots.length; j++) { thresh.add(j, threshold); } my_data_series.addSeries(thresh); System.out.println(d.name); JFreeChart XYLineChart = ChartFactory.createXYLineChart(d.name, "Position", "Average", my_data_series, PlotOrientation.VERTICAL, true, true, false); bImage1 = (BufferedImage) XYLineChart.createBufferedImage(600, 300); ImageIcon imageIcon = new ImageIcon(bImage1); jLabel1.setIcon(imageIcon); }