Example usage for org.jfree.chart JFreeChart createBufferedImage

List of usage examples for org.jfree.chart JFreeChart createBufferedImage

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart createBufferedImage.

Prototype

public BufferedImage createBufferedImage(int width, int height) 

Source Link

Document

Creates and returns a buffered image into which the chart has been drawn.

Usage

From source file:zw.co.hitrac.tpg.web.chart.PerformanceChart.java

@Override
protected IResource getImageResource() {
    return new DynamicImageResource() {

        @Override//  w  ww. jav  a 2 s.  c om
        protected byte[] getImageData(IResource.Attributes atrbts) {
            JFreeChart chart = createData();
            return toImageData(chart.createBufferedImage(width, height));
        }
    };
}

From source file:org.mt4jx.components.visibleComponents.widgets.jfreechart.MTJFreeChart.java

public MTJFreeChart(float sizeX, float sizeY, PApplet pApplet, JFreeChart jFreeChart) {
    super(new PImage(jFreeChart.createBufferedImage(Math.round(sizeX), Math.round(sizeY))), pApplet);
    this.createScaleListener();
    this.setJFreeChart(jFreeChart);
    if (redrawWhenScaled) {
        this.addGestureListener(ScaleProcessor.class, this.scaleAction);
    }//from  ww  w. j a v a  2  s  .c o  m
}

From source file:au.org.theark.core.web.component.chart.JFreeChartImage.java

@Override
protected IResource getImageResource() {
    DynamicImageResource resource = new DynamicImageResource() {

        private static final long serialVersionUID = 1L;

        @Override/*from w w  w  . ja  va 2  s. co  m*/
        protected byte[] getImageData(final Attributes attributes) {
            JFreeChart chart = (JFreeChart) getDefaultModelObject();
            return toImageData(chart.createBufferedImage(width, height));
        }

        @Override
        protected void configureResponse(final ResourceResponse response, final Attributes attributes) {
            super.configureResponse(response, attributes);
            response.setCacheDuration(Duration.NONE);
            response.setCacheScope(CacheScope.PRIVATE);
        }

    };

    return resource;
}

From source file:org.patientview.radar.web.components.JFreeChartImage.java

@Override
protected IResource getImageResource() {
    DynamicImageResource resource = new DynamicImageResource() {

        @Override/*from w w w  .j  a  v a 2 s.  c  o  m*/
        protected byte[] getImageData(final Attributes attributes) {
            JFreeChart chart = (JFreeChart) getDefaultModelObject();
            return toImageData(chart.createBufferedImage(width, height));
        }

        @Override
        protected void configureResponse(final ResourceResponse response, final Attributes attributes) {
            super.configureResponse(response, attributes);

            response.setCacheDuration(Duration.NONE);
            response.setCacheScope(WebResponse.CacheScope.PRIVATE);

        }

    };

    return resource;
}

From source file:com.datamyne.charts.UglyDemo.java

/**
 * Creates PDf file./*www .jav a 2 s  .  c o  m*/
 * @param outputStream {@link OutputStream}.
 * @throws DocumentException
 * @throws IOException
 */
public void create(OutputStream outputStream) throws DocumentException, IOException {
    Document document = null;
    PdfWriter writer = null;

    try {
        //instantiate document and writer
        document = new Document();
        writer = PdfWriter.getInstance(document, outputStream);

        //open document
        document.open();

        //add image
        int width = 300;
        int height = 300;
        JFreeChart chart = getChart();
        BufferedImage bufferedImage = chart.createBufferedImage(width, height);
        Image image = Image.getInstance(writer, bufferedImage, 1.0f);
        document.add(image);

        //release resources
        document.close();
        document = null;

        writer.close();
        writer = null;
    } catch (DocumentException de) {
        throw de;
    } catch (IOException ioe) {
        throw ioe;
    } finally {
        //release resources
        if (null != document) {
            try {
                document.close();
            } catch (Exception ex) {
            }
        }

        if (null != writer) {
            try {
                writer.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:com.datamyne.charts.FixingUglyDemoByScaling.java

/**
 * Creates PDf file.//www.  j a  v a2 s.  com
 * @param outputStream {@link OutputStream}.
 * @throws DocumentException
 * @throws IOException
 */
public void create(OutputStream outputStream) throws DocumentException, IOException {
    Document document = null;
    PdfWriter writer = null;

    try {
        //instantiate document and writer
        document = new Document();
        writer = PdfWriter.getInstance(document, outputStream);

        //open document
        document.open();

        //add image
        int width = 300;
        int height = 300;
        float fWidth = 0.6f * width;
        float fHeight = 0.6f * height;
        JFreeChart chart = getChart();
        BufferedImage bufferedImage = chart.createBufferedImage(width, height);
        Image image = Image.getInstance(writer, bufferedImage, 1.0f);
        image.scaleAbsolute(fWidth, fHeight);
        document.add(image);

        //release resources
        document.close();
        document = null;

        writer.close();
        writer = null;
    } catch (DocumentException de) {
        throw de;
    } catch (IOException ioe) {
        throw ioe;
    } finally {
        //release resources
        if (null != document) {
            try {
                document.close();
            } catch (Exception ex) {
            }
        }

        if (null != writer) {
            try {
                writer.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:hudson.model.LoadStatisticsTest.java

public void testGraph() throws IOException {
    LoadStatistics ls = new LoadStatistics(0, 0) {
        public int computeIdleExecutors() {
            throw new UnsupportedOperationException();
        }/*from  ww  w  .  j av  a  2  s  .c  o  m*/

        public int computeTotalExecutors() {
            throw new UnsupportedOperationException();
        }

        public int computeQueueLength() {
            throw new UnsupportedOperationException();
        }
    };

    for (int i = 0; i < 50; i++) {
        ls.totalExecutors.update(4);
        ls.busyExecutors.update(3);
        ls.queueLength.update(3);
    }

    for (int i = 0; i < 50; i++) {
        ls.totalExecutors.update(0);
        ls.busyExecutors.update(0);
        ls.queueLength.update(1);
    }

    JFreeChart chart = ls.createTrendChart(TimeScale.SEC10).createChart();
    BufferedImage image = chart.createBufferedImage(400, 200);

    File tempFile = File.createTempFile("chart-", "png");
    FileOutputStream os = new FileOutputStream(tempFile);
    try {
        ImageIO.write(image, "PNG", os);
    } finally {
        IOUtils.closeQuietly(os);
        tempFile.delete();
    }
}

From source file:org.optaplanner.benchmark.impl.statistic.ProblemStatistic.java

protected File writeChartToImageFile(JFreeChart chart, String fileNameBase) {
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    File chartFile = new File(problemBenchmarkResult.getProblemReportDirectory(), fileNameBase + ".png");
    OutputStream out = null;/* w w w .ja  va2  s .  co  m*/
    try {
        out = new FileOutputStream(chartFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing chartFile: " + chartFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
    return chartFile;
}

From source file:io.narayana.perf.product.BarChart.java

private void writeImageData(JFreeChart chart, String imageFileName, String formatName) throws IOException {
    BufferedImage objBufferedImage = chart.createBufferedImage(600, 300);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(objBufferedImage, "png", baos);
    byte[] byteArray = baos.toByteArray();
    InputStream in = new ByteArrayInputStream(byteArray);
    BufferedImage image = ImageIO.read(in);
    File outputfile = new File(imageFileName);

    ImageIO.write(image, formatName, outputfile);

    System.out.printf("GENERATED IMAGE FILE TO %s%n", outputfile.getCanonicalPath());
}

From source file:org.sonar.api.charts.AbstractChart.java

/**
 * Generates a JFreeChart chart using a set of parameters
 * // w  w w.j a  va 2s.  co  m
 * @param params the chart parameters
 * @return the generated chart
 */
public BufferedImage generateImage(ChartParameters params) {
    JFreeChart chart = new JFreeChart(null, TextTitle.DEFAULT_FONT, getPlot(params), hasLegend());
    improveChart(chart, params);
    return chart.createBufferedImage(params.getWidth(), params.getHeight());
}