Example usage for org.jfree.chart ChartUtilities saveChartAsJPEG

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

Introduction

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

Prototype

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

Source Link

Document

Saves a chart to a file in JPEG format.

Usage

From source file:com.main.controller.ChartDIG.java

public File generateBarChart() throws Exception {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (String string : arrayList) {
        dataset.addValue(Integer.parseInt(string), string, string);
    }/*from ww  w  .  ja v a2  s  .  c o  m*/

    JFreeChart barChart = ChartFactory.createBarChart(chartTitle, xTitle, yTitle, dataset,
            PlotOrientation.VERTICAL, true, true, false);

    //        int width = 640;
    //        /* Width of the image */
    //        int height = 480;
    /* Height of the image */
    File BarChart = new File("chart/" + chartTitle + ".jpeg");
    ChartUtilities.saveChartAsJPEG(BarChart, barChart, width, height);
    return BarChart;
}

From source file:overTrial.CreateGraphOverTrial.java

public CreateGraphOverTrial(String applicationTitle, String chartTitle, LinkedList<LinkedList<String>> pData,
        int sensorNum, String sessionNo) {
    super(applicationTitle);
    this.pressureData = pData;
    this.sensorNumber = sensorNum;
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, sessionNo,
            "Average Pressure Value over the time(per trail)", createDataset(), PlotOrientation.VERTICAL, true,
            true, false);//  w ww  .  j  av  a2s .  c om
    //lineChart.setBackgroundPaint(Color.red);
    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1200, 500));
    setContentPane(chartPanel);

    File fileLineChart = new File(sessionNo + "_sensor" + this.sensorNumber + ".jpeg");
    try {
        ChartUtilities.saveChartAsJPEG(fileLineChart, lineChart, 1200, 500);
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:overTrialSensorSubDivided.CreateGraphSubDivided.java

public CreateGraphSubDivided(String applicationTitle, String chartTitle, LinkedList<LinkedList<String>> pData,
        int sensorNum, String sessionNo) {
    super(applicationTitle);
    this.pressureData = pData;
    this.sensorNumber = sensorNum;
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, sessionNo,
            "Average Pressure Value over the time(per trail)", createDataset(), PlotOrientation.VERTICAL, true,
            true, false);//from w w  w  .  j a  v a2  s .c o  m
    //lineChart.setBackgroundPaint(Color.red);
    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(700, 500));
    setContentPane(chartPanel);

    File fileLineChart = new File(sessionNo + "_sensor" + this.sensorNumber + ".jpeg");
    try {
        ChartUtilities.saveChartAsJPEG(fileLineChart, lineChart, 1100, 500);
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:overTrialFluctuations.CreateGraphTrialFluctuations.java

public CreateGraphTrialFluctuations(String applicationTitle, String chartTitle,
        LinkedList<LinkedList<String>> pData, int sensorNum, String sessionNo) {
    super(applicationTitle);
    this.pressureData = pData;
    this.sensorNumber = sensorNum;
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, sessionNo,
            "Average Pressure Value over the time(per trail)", createDataset(), PlotOrientation.VERTICAL, true,
            true, false);//from  www. ja  v  a 2  s.  co  m
    //lineChart.setBackgroundPaint(Color.red);
    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(700, 500));
    setContentPane(chartPanel);

    File fileLineChart = new File(sessionNo + "_sensor" + this.sensorNumber + ".jpeg");
    try {
        ChartUtilities.saveChartAsJPEG(fileLineChart, lineChart, 1100, 500);
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:co.udea.edu.proyectointegrador.gr11.parqueaderoapp.domain.stadistics.graphics.implement.GraficaTest.java

/**
 * Test of createPieToUserType method, of class Grafica.
 *///from   ww  w  . j  av  a 2  s  . c  om
@Test
public void testCreatePieToUserType() throws Exception {
    String startDate = "2014-07-04 18:14:29.000";
    String endDate = "2017-07-04 18:14:29.000";
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
    Date startD = dateFormat.parse(startDate);
    Date endD = dateFormat.parse(endDate);
    JFreeChart chart = g.createPieToUserType(controller.getEstadisticasByTipoUsuario(startD, endD));
    ChartUtilities.saveChartAsJPEG(new File("D:\\chart2.JPG"), chart, 400, 300);
}

From source file:skyc.ViewContent.java

public void saveChart(JFreeChart chart) {
    String fileName = "Chart.jpg";
    try {//from w w  w  .j a v a2 s.  co  m
        /**
         * This utility saves the JFreeChart as a JPEG
         * First Parameter: FileName
         * Second Parameter: Chart To Save
         * Third Parameter: Height Of Picture
         * Fourth Parameter: Width Of Picture
         */
        ChartUtilities.saveChartAsJPEG(new File(fileName), chart, 800, 600);
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Problem occurred creating chart.");
    }
}

From source file:ip.ui.plot.PlotGenerator.java

public void generateErrorChart(List<Double> errors, String plotFileName) throws IOException {
    XYSeries data = new XYSeries("Errors");

    for (int i = 1; i <= errors.size(); ++i) {
        data.add(i, errors.get(i - 1));/*from w ww  .  j a  va  2s. co m*/
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(data);
    JFreeChart chart = ChartFactory.createXYLineChart("Squared error", "Epoch number", "Squared Error", dataset,
            PlotOrientation.VERTICAL, false, true, true);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    chart.getXYPlot().setRenderer(renderer);

    File XYChart = new File(plotFileName);
    ChartUtilities.saveChartAsJPEG(XYChart, chart, chartWidth, chartHeight);
}

From source file:be.pendragon.j2s.seventhcontinent.plot.jfreechart.JFreeChartPlotter.java

@Override
public void plot(Statistics[] stats, String[] seriesNames, String title, File outputFile) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int series = 0; series < stats.length; series++) {
        for (int pct = 1; pct <= 100; pct++) {
            double pctValue = stats[series].getPercentile(pct); // # of stars
            if (series > 0) {
                pctValue = pctValue - stats[series - 1].getPercentile(pct); // deltas are stackables
            }//www .jav  a 2s  .co m
            dataset.addValue(pctValue, seriesNames[series], new Integer(pct));
        }
    }
    final JFreeChart barChart = ChartFactory.createStackedBarChart(title, "%", "# stars", dataset);
    try {
        ChartUtilities.saveChartAsJPEG(outputFile, barChart, width, height);
    } catch (IOException ex) {
        //      LOG.log(Level.SEVERE, "Plotting chart to file", ex);
        throw new RuntimeException("Plotting with JFreeChart chart to file", ex);
    }
}

From source file:sipl.recursos.Graficar.java

public boolean TipoMaterial(ArrayList<Tipo_material> TM, String direccion) throws IOException {
    boolean flag = false;
    DefaultPieDataset data = new DefaultPieDataset();
    for (int i = 0; i < TM.size(); i++) {
        data.setValue("Cat." + TM.get(i).getId(), TM.get(i).getCantidad());
    }/*from   w  ww .  java 2s.c o  m*/
    JFreeChart chart = ChartFactory.createPieChart("Cantidad de materiales por categora", data, true, true,
            true);
    try {
        ChartUtilities.saveChartAsJPEG(new File(direccion), chart, 500, 500);
        flag = true;
    } catch (IOException e) {
        System.out.println("Error al abrir el archivo");
    }
    return flag;
}

From source file:graficos.GenerarGraficoInventario.java

public void crear() {
    try {/*from   w  w w . j  a v  a  2  s .  com*/
        Dba db = new Dba(pathdb);
        db.conectar();
        String sql = "select Nombre, CantidadDisponibles, CantidadEnUso from Activos";
        db.prepare(sql);
        db.query.execute();
        ResultSet rs = db.query.getResultSet();
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        while (rs.next()) {
            int total = rs.getInt(2) + rs.getInt(3);
            dataset.setValue(total, "Cantidad", rs.getString(1));
        }

        JFreeChart chart = ChartFactory.createBarChart3D("Inventario de Activos del Hotel", "Activo",
                "Cantidad", dataset, PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot(); // Get the Plot object for a bar graph
        p.setBackgroundPaint(Color.black);
        ((BarRenderer) p.getRenderer()).setBarPainter(new StandardBarPainter());

        BarRenderer r = (BarRenderer) chart.getCategoryPlot().getRenderer();
        r.setSeriesPaint(0, Color.BLUE);

        try {
            ChartUtilities.saveChartAsJPEG(new File(path), chart, 500, 300);
        } catch (Exception ee) {
            System.err.println(ee.toString());
            System.err.println("Problem occurred creating chart.");
        }

        db.desconectar();
    } catch (Exception e) {

    }

}