Example usage for org.jfree.chart.util ExportUtils writeAsPNG

List of usage examples for org.jfree.chart.util ExportUtils writeAsPNG

Introduction

In this page you can find the example usage for org.jfree.chart.util ExportUtils writeAsPNG.

Prototype

public static void writeAsPNG(Drawable drawable, int w, int h, File file)
        throws FileNotFoundException, IOException 

Source Link

Document

Writes the current content to the specified file in PNG format.

Usage

From source file:com.artnaseef.jmeter.report.ResultCodesPerSecondReport.java

@Override
public void onFeedComplete() throws Exception {
    this.calculateTimeAdjustments();

    this.populateSeries(this.feedUri);

    for (XYSeries oneSeries : this.chartSeries) {
        this.dataset.addSeries(oneSeries);
    }/* w w w. j av a 2s.  co  m*/

    this.createChart();

    ExportUtils.writeAsPNG(this.chart, this.reportWidth, this.reportHeight, new File(this.outputFile));
}

From source file:com.artnaseef.jmeter.report.HitsPerSecondReport.java

protected void finishReport() throws Exception {
    this.populateSeries(this.feedUri);
    this.dataset.addSeries(this.chartSeries);
    this.createChart();

    ExportUtils.writeAsPNG(this.chart, this.reportWidth, this.reportHeight, new File(this.outputFile));
}

From source file:com.artnaseef.jmeter.report.ResultCodesStackedReport.java

@Override
public void onFeedComplete() throws Exception {
    this.adjustSlots();

    this.calculateTimeCustomizations();

    this.populateSeries(this.feedUri);

    this.createChart();

    ExportUtils.writeAsPNG(this.chart, this.reportWidth, this.reportHeight, new File(this.outputFile));
}

From source file:io.github.mzmine.util.jfreechart.JFreeChartUtils.java

public static void exportToImageFile(ChartViewer chartNode, File file, ImgFileType fileType) {

    final JFreeChart chart = chartNode.getChart();
    final int width = (int) chartNode.getWidth();
    final int height = (int) chartNode.getHeight();

    try {/* www.  j  av a2  s.c o m*/

        switch (fileType) {

        case JPG:
            ExportUtils.writeAsJPEG(chart, width, height, file);
            break;

        case PNG:
            ExportUtils.writeAsPNG(chart, width, height, file);
            break;

        case SVG:
            setDrawSeriesLineAsPath(chart, true);
            ExportUtils.writeAsSVG(chart, width, height, file);
            setDrawSeriesLineAsPath(chart, false);
            break;

        case PDF:
            setDrawSeriesLineAsPath(chart, true);
            ExportUtils.writeAsPDF(chart, width, height, file);
            setDrawSeriesLineAsPath(chart, false);
            break;

        case EMF:
            FileOutputStream out2 = new FileOutputStream(file);
            setDrawSeriesLineAsPath(chart, true);
            EMFGraphics2D g2d2 = new EMFGraphics2D(out2, new Dimension(width, height));
            g2d2.startExport();
            chart.draw(g2d2, new Rectangle(width, height));
            g2d2.endExport();
            setDrawSeriesLineAsPath(chart, false);
            break;

        case EPS:
            FileOutputStream out = new FileOutputStream(file);
            setDrawSeriesLineAsPath(chart, true);
            EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
            g2d.setGraphicContext(new GraphicContext());
            g2d.setupDocument(out, width, height);
            chart.draw(g2d, new Rectangle(width, height));
            g2d.finish();
            setDrawSeriesLineAsPath(chart, false);
            out.close();
            break;

        }

    } catch (IOException e) {
        MZmineGUI.displayMessage("Unable to save image: " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java

/**
 * A handler for the export to PNG option in the context menu.
 *//*w ww  . j a  va2s.  c o  m*/
private void handleExportToPNG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to PNG");
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Portable Network Graphics (PNG)", "png"));
    File file = fileChooser.showSaveDialog(this.getScene().getWindow());
    if (file != null) {
        try {
            ExportUtils.writeAsPNG(this.chart, (int) getWidth(), (int) getHeight(), file);
        } catch (IOException ex) {
            // FIXME: show a dialog with the error
        }
    }
}