List of usage examples for org.jfree.chart JFreeChart createBufferedImage
public BufferedImage createBufferedImage(int width, int height)
From source file:de.aidger.view.utils.Charts.java
/** * Creates a xy area chart./*from w w w .j av a 2s . 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 xy area chart as image */ public static ImageIcon createXYAreaChart(String title, XYDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createXYAreaChart(title, "", "", dataset, PlotOrientation.VERTICAL, false, false, false); Font titleFont = UIManager.getFont("TitledBorder.font"); chart.setBackgroundPaint(null); chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14)); chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor")); chart.setBorderPaint(null); XYPlot plot = chart.getXYPlot(); plot.setInsets(new RectangleInsets(10, 1, 5, 1)); plot.setBackgroundPaint(null); plot.setOutlineVisible(false); plot.setNoDataMessage(_("No data to display.")); ValueAxis domainAxis = new DateAxis(); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setTickLabelFont(UIManager.getFont("RootPane.font")); ValueAxis rangeAxis = new NumberAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setDomainAxis(domainAxis); plot.setRangeAxis(rangeAxis); plot.setForegroundAlpha(0.5f); return new ImageIcon(chart.createBufferedImage(width, height)); }
From source file:user.CreateChart.java
private ImageIcon PieChart(DefaultPieDataset dataset, String name) { JFreeChart chart = ChartFactory.createPieChart(name, // chart title dataset, // data true, // include legend true, false);//from w ww.j a va 2 s . co m ImageIcon ii = new ImageIcon(chart.createBufferedImage(592, 500)); return ii; }
From source file:ufmotionsuite.SpiralGraph.java
public void Graph() { XYSeries series = new XYSeries("X vs Y"); for (int i = 0; i < arrLength; i++) { //System.out.println("Run"); series.add(theta[i], r[i]);// ww w. j ava 2 s. c o m } XYDataset dataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart("Distance from Origin over Angle", "Theta", "R (Distance)", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, false, false); BufferedImage image = chart.createBufferedImage(600, 600); jLabel1.setIcon(new ImageIcon(image)); this.setSize(800, 800); }
From source file:org.drools.planner.benchmark.core.statistic.calculatecount.CalculateCountProblemStatistic.java
protected void writeGraphStatistic() { XYSeriesCollection seriesCollection = new XYSeriesCollection(); for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) { CalculateCountSingleStatistic singleStatistic = (CalculateCountSingleStatistic) singleBenchmark .getSingleStatistic(problemStatisticType); XYSeries series = new XYSeries(singleBenchmark.getSolverBenchmark().getName()); for (CalculateCountSingleStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpend = point.getTimeMillisSpend(); long calculateCountPerSecond = point.getCalculateCountPerSecond(); series.add(timeMillisSpend, calculateCountPerSecond); }/*from w w w. ja v a 2 s . com*/ seriesCollection.addSeries(series); } NumberAxis xAxis = new NumberAxis("Time 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(problemBenchmark.getName() + " calculate count statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); graphStatisticFile = new File(problemBenchmark.getProblemReportDirectory(), problemBenchmark.getName() + "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); } }
From source file:org.drools.planner.benchmark.core.statistic.memoryuse.MemoryUseProblemStatistic.java
protected void writeGraphStatistic() { XYSeriesCollection seriesCollection = new XYSeriesCollection(); for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) { MemoryUseSingleStatistic singleStatistic = (MemoryUseSingleStatistic) singleBenchmark .getSingleStatistic(problemStatisticType); XYSeries usedSeries = new XYSeries(singleBenchmark.getSolverBenchmark().getName() + " used"); XYSeries maxSeries = new XYSeries(singleBenchmark.getSolverBenchmark().getName() + " max"); for (MemoryUseSingleStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpend = point.getTimeMillisSpend(); MemoryUseMeasurement memoryUseMeasurement = point.getMemoryUseMeasurement(); usedSeries.add(timeMillisSpend, memoryUseMeasurement.getUsedMemory()); maxSeries.add(timeMillisSpend, memoryUseMeasurement.getMaxMemory()); }/*from w w w . j av a 2 s . c om*/ seriesCollection.addSeries(usedSeries); seriesCollection.addSeries(maxSeries); } NumberAxis xAxis = new NumberAxis("Time 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(problemBenchmark.getName() + " memory use statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); graphStatisticFile = new File(problemBenchmark.getProblemReportDirectory(), problemBenchmark.getName() + "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); } }
From source file:org.xwiki.chart.internal.DefaultChartGenerator.java
/** * {@inheritDoc}//from w w w. ja v a2 s .co m */ public byte[] generate(ChartModel model, Map<String, String> parameters) throws ChartGeneratorException { setDefaultParams(parameters); String type = parameters.get(TYPE_PARAM); String title = parameters.get(TITLE_PARAM); PlotGenerator generator = plotGenerators.get(type); if (null == generator) { throw new ChartGeneratorException(String.format("No such chart type : [%s].", type)); } Plot plot = generator.generate(model, parameters); JFreeChart jfchart = new JFreeChart(title, plot); int width = Integer.parseInt(parameters.get(WIDTH_PARAM)); int height = Integer.parseInt(parameters.get(HEIGHT_PARAM)); try { return ChartUtilities.encodeAsPNG(jfchart.createBufferedImage(width, height)); } catch (IOException ex) { throw new ChartGeneratorException("Error while png encoding the chart image."); } }
From source file:br.com.oncast.dev.lobo.report.JFreeChartReportPlotter.java
/** * Plot a graphic for the {@link MetricAndValues}. * @param metricAndValues The source for the graphic. * @param baseDir The base dir for plot the graphics. * @throws IOException in case of exception on writing the image. *//*w w w . ja va 2 s. c o m*/ private void plotGraphic(final MetricAndValues metricAndValues, final File baseDir) throws IOException { final MergeMetric mergeMetric = metricAndValues.mergeMetric; final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (final MetricValue metricValue : metricAndValues.metricValues) dataset.addValue(metricValue.getValue(), mergeMetric.getMetric(), metricValue.getBuildName()); final JFreeChart chart = ChartFactory.createLineChart(mergeMetric.getMetric(), TITLE_BUILD, TITLE_VALUE, dataset, PlotOrientation.VERTICAL, true, false, false); final BufferedImage bufferedImage = chart.createBufferedImage(GRAPHIC_WIDTH, GRAPHIC_HEIGHT); final String filePath = mergeMetric.getCase() + "/"; final String fileName = mergeMetric.getScenario() + "-" + mergeMetric.getMetric() + "." + GRAPHIC_FORMAT; final String fullFileName = filePath + fileName; final File outputFileImage = new File(baseDir, fullFileName); outputFileImage.getParentFile().mkdirs(); ImageIO.write(bufferedImage, GRAPHIC_FORMAT, outputFileImage); }
From source file:org.atomserver.testutils.plot.PerfPlotter.java
/** *///w w w. jav a 2s . c o m public JFreeChart createPlot(XYDataset dataSet) { JFreeChart chart = createChart(dataSet); if (log.isTraceEnabled()) log.trace("chart= " + chart); try { java.awt.image.BufferedImage buffImage = chart.createBufferedImage(width, hieght); if (log.isTraceEnabled()) log.trace("buffImage= " + buffImage); org.jfree.chart.encoders.SunPNGEncoderAdapter pngEncoder = new org.jfree.chart.encoders.SunPNGEncoderAdapter(); java.io.FileOutputStream fileOS = new java.io.FileOutputStream(pngFileName); if (log.isTraceEnabled()) log.trace("fileOS= " + fileOS); pngEncoder.encode(buffImage, fileOS); fileOS.close(); if (log.isTraceEnabled()) log.trace("PNG file created sucessfully!!!!"); } catch (Exception ee) { log.error(ee); return null; } return chart; }
From source file:org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore.java
private String generateHeatChart(final TSTable info, final TimeSeries data, final int width, final int height) throws IOException { JFreeChart chart = TimeSeriesDatabase.createHeatJFreeChart(data, info); BufferedImage img = chart.createBufferedImage(width, height); File dbFile = new File(database.getDBFilePath()); File graphicFile = File.createTempFile(dbFile.getName() + "_" + fixName(info.getTableName()), ".dist.png", dbFile.getParentFile());/*from w w w . j a v a2 s . com*/ ImageIO.write(img, "png", graphicFile); return graphicFile.getAbsolutePath(); }
From source file:common.AbstractGUI.java
protected void writePNG(JFreeChart jFreeChart, File snapshotDir, String name) { if (jFreeChart != null) { BufferedImage cpuImage = jFreeChart.createBufferedImage(833, 500); File cpuFile = new File(snapshotDir.getPath() + File.separatorChar + name); try {// w ww . j av a 2 s . c o m ImageIO.write(cpuImage, "PNG", cpuFile); } catch (IOException e) { log(e.getMessage()); } } }