Example usage for org.jfree.chart ChartUtilities saveChartAsPNG

List of usage examples for org.jfree.chart ChartUtilities saveChartAsPNG

Introduction

In this page you can find the example usage for org.jfree.chart ChartUtilities saveChartAsPNG.

Prototype

public static void saveChartAsPNG(File file, JFreeChart chart, int width, int height) throws IOException 

Source Link

Document

Saves a chart to the specified file in PNG format.

Usage

From source file:org.jfree.chart.demo.SparklineDemo1.java

public static void main(String args[]) {
    XYSeries xyseries = new XYSeries("Series 1");
    xyseries.add(1.0D, 1.0D);/*from w  ww  .j  av  a  2  s.  co  m*/
    xyseries.add(2D, 3D);
    xyseries.add(3D, 2D);
    xyseries.add(4D, 4D);
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    xyseriescollection.addSeries(xyseries);
    JFreeChart jfreechart = ChartFactory.createXYLineChart(null, "X", "Y", xyseriescollection,
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setInsets(RectangleInsets.ZERO_INSETS);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setRangeGridlinesVisible(false);
    xyplot.setOutlinePaint(null);
    xyplot.getDomainAxis().setVisible(false);
    xyplot.getRangeAxis().setVisible(false);
    try {
        ChartUtilities.saveChartAsPNG(new File("Sparky.png"), jfreechart, 100, 20);
    } catch (IOException ioexception) {
        ioexception.printStackTrace();
    }
}

From source file:statistique.PieChart3D.java

public static void main(String[] args) throws Exception {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("IPhone 5s", new Double(20));
    dataset.setValue("SamSung Grand", new Double(20));
    dataset.setValue("MotoG", new Double(40));
    dataset.setValue("Nokia Lumia", new Double(10));

    JFreeChart chart = ChartFactory.createPieChart3D("Mobile Sales", // chart title                   
            dataset, // data 
            true, // include legend                   
            true, false);//from   w  w  w . j a va 2s . com

    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(270);
    plot.setForegroundAlpha(0.60f);
    plot.setInteriorGap(0.02);
    int width = 640; /* Width of the image */
    int height = 480; /* Height of the image */
    File pieChart3D = new File("pie_Chart3D.png");
    ChartUtilities.saveChartAsPNG(pieChart3D, chart, width, height);
}

From source file:playground.wrashid.tryouts.mess.Boxplot.java

/**
 * @param args/*from   w  w  w  .ja v  a2s.  c  o m*/
 */
public static void main(String[] args) {

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset();

    final CategoryAxis xAxis = new CategoryAxis("Type");
    final NumberAxis yAxis = new NumberAxis("Value");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Box-and-Whisker Demo", "x", "y", dataset,
            true);
    final ChartPanel chartPanel = new ChartPanel(chart);

    int width = 500;
    int height = 300;

    try {
        ChartUtilities.saveChartAsPNG(new File("boxPlot.png"), chart, width, height);
    } catch (IOException e) {

    }

}

From source file:vis2006.VisGrafik.java

public void saveToJPEG(String dir) {
    //        File fn= new File(dir, "grafik.jpg");

    File fn = new File(dir, "grafik" + graphType + ".png");
    ChartUtilities ut = null;
    try {/*from   ww  w.j ava  2 s  .c o  m*/
        //            ut.saveChartAsJPEG(fn ,jfreeChart,  800, 800);
        ut.saveChartAsPNG(fn, jfreeChart, 400, 400);
    } catch (Exception e) {
        System.out.println(e);
    }

}

From source file:com.graphhopper.jsprit.analysis.toolbox.XYLineChartBuilder.java

/**
 * Helper that just saves the chart as specified png-file. The width of the image is 1000 and height 600.
 *
 * @param chart//ww w.j  av a2 s.  c  om
 * @param pngFilename
 */
public static void saveChartAsPNG(JFreeChart chart, String pngFilename) {
    try {
        ChartUtilities.saveChartAsPNG(new File(pngFilename), chart, 1000, 600);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:ch.zhaw.parallelComputing.view.Plotter.java

/**
 * Creates a PNG plot of the given data set
 * @param title the name of the plot picture
 * @param dataset1 the first data set for plotting
 * @param dataset2 the second data set for plotting
 *//*from   www.j  a v  a2 s .  co m*/
public static void getPlotAsPNG(String title, XYDataset dataset1, XYDataset dataset2) {
    JFreeChart chart = plot(title, dataset1, dataset2);
    try {
        ChartUtilities.saveChartAsPNG(new File(title + ".png"), chart, 1920, 1080);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }
}

From source file:adept.utilities.Grapher.java

/**
 * Make heap usage graph.//from ww w. j a  v  a2s.  c om
 *
 * @param values the values
 * @param filename the filename
 */
public static void makeHeapUsageGraph(ArrayList<Double> values, File filename) {
    try {
        DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset();
        for (int i = 1; i <= values.size(); i++) {
            line_chart_dataset.addValue(values.get(i - 1), "MB", "" + i);
        }

        /* Step -2:Define the JFreeChart object to create line chart */
        JFreeChart lineChartObject = ChartFactory.createLineChart("Heap Memory Usage", "Run Number",
                "Heap Memory Used", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false);

        /* Step -3 : Write line chart to a file */
        int width = 640; /* Width of the image */
        int height = 480; /* Height of the image */
        ChartUtilities.saveChartAsPNG(filename, lineChartObject, width, height);
    }

    catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Diagramas.LineChart_AWT.java

public LineChart_AWT(String applicationTitle, String chartTitle) throws IOException {
    super(applicationTitle);
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Years", "Number of Schools",
            createDataset(), PlotOrientation.VERTICAL, true, true, false);

    int width = 640; /* Width of the image */
    int height = 480; /* Height of the image */
    File lineCharts = new File("LineChart.png");
    ChartUtilities.saveChartAsPNG(lineCharts, lineChart, width, height);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    setContentPane(chartPanel);/*from  w  ww .j  av  a 2s  .  co  m*/
}

From source file:Diagramas.BarChart_AWT.java

public BarChart_AWT(String applicationTitle, String chartTitle) throws IOException {
    super(applicationTitle);
    JFreeChart barChart = ChartFactory.createBarChart(chartTitle, "Category", "Score", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);

    int width = 640; /* Width of the image */
    int height = 480; /* Height of the image */
    File BarChart = new File("BarChart.png");
    ChartUtilities.saveChartAsPNG(BarChart, barChart, width, height);

    ChartPanel chartPanel = new ChartPanel(barChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    setContentPane(chartPanel);//ww  w  .  j  a  v a 2 s.  c  o  m
}

From source file:org.gwaspi.gui.TestReports.java

public static File createCombinedPNGFromAssocUnadjLogPvsPos(File plinkReport, File outputFile,
        Set<String> redMarkers, int width, int height) throws FileNotFoundException, IOException {
    // Generating XY scatter plot with loaded data
    CombinedRangeXYPlot combinedPlot = org.gwaspi.reports.PlinkReportLoaderCombined
            .loadAssocUnadjLogPvsPos(plinkReport, redMarkers);

    JFreeChart chart = new JFreeChart("P value x Chr position", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot,
            true);// w  ww.  j av a2 s.co m

    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, width, height);
    } catch (IOException ex) {
        log.error("Problem occurred creating chart", ex);
    }

    return null;
}