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:sipl.recursos.Graficar.java

public void TipoMaterialBarras(ArrayList<Tipo_material> TM, String direccion) throws IOException {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < TM.size(); i++) {
        Tipo_material mat = TM.get(i);/* w  w w . j  av  a2 s .co m*/
        dataset.addValue(mat.getCantidad(), "" + mat.getCantidad(), "" + mat.getId());
    }
    JFreeChart chart = ChartFactory.createBarChart("Cantidad de materiales por categora", "Categora(Y)",
            "Cantidad(X)", dataset, PlotOrientation.HORIZONTAL, true, true, false);
    try {
        ChartUtilities.saveChartAsJPEG(new File(direccion), chart, 800, 400);
    } catch (IOException e) {
        System.out.println("Error al abrir el archivo");
    }
}

From source file:com.mycompany.task1.Chart.java

public void makeChart(int kolumna) {

    SortedSet sortedSet = calculation.getClassTypeCollection();
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    for (Object object : sortedSet) {
        Map<Double, Integer> mapa = calculation.histogramData(kolumna, object);
        loadData(mapa, object, dataSet);
    }//from w ww.  jav a  2  s  .  c om
    try {
        JFreeChart chart = displayChart(dataSet);
        ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 1000, 700);
    } catch (IOException ex) {
        Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.decypher.threadsclient.JPanelChart.java

public void saveAsImage() {

    String folder = getFolder();/*w  w  w .j av a  2  s  . c o m*/
    if (!folder.isEmpty()) {
        String location = folder + "/" + UUID.randomUUID().toString() + ".jpeg";
        int width = 1280;
        int height = 960;
        try {
            File imgChart = new File(location);
            ChartUtilities.saveChartAsJPEG(imgChart, chart, width, height);
            Desktop.getDesktop().open(new File(folder));
        } catch (IOException ex) {
            Extra.MessageBox.Show(ex.getMessage(), Extra.Title.Error);
        }
    }
}

From source file:pdfboxtest.HistandVolChart.java

public File chart(String ticker, int numberOfYears) throws Exception {
    BufferedReader reader = null;
    String splitBy = ",";
    String line;//ww  w  .  ja v  a2  s .c  o  m
    double stockPrice;
    File file = new File(
            "C:\\Users\\Matthew\\Documents\\NetBeansProjects\\TradingData\\ticker\\" + ticker + ".data");
    reader = new BufferedReader(new FileReader(file));

    DefaultCategoryDataset stockDataSet = new DefaultCategoryDataset();
    while (reader.readLine() != null) {
        line = reader.readLine();
        String[] stockData = line.split(splitBy);
        stockPrice = Double.parseDouble(stockData[0]);
        stockDataSet.addValue(stockPrice, ticker, line);
    }

    JFreeChart chartObject = ChartFactory.createLineChart(null, null, null, stockDataSet,
            PlotOrientation.VERTICAL, false, false, false);
    int width = 300;
    int height = 200;
    File chart = new File("C:\\Users\\Matthew\\Documents\\NetBeansProjects\\PDFBoxTest\\" + ticker + ".jpg");
    ChartUtilities.saveChartAsJPEG(chart, chartObject, width, height);
    return chart;
}

From source file:estimatePressure.CreateGraph.java

public CreateGraph(String applicationTitle, String chartTitle, Matrix errData, int sensorNum) {
    super(applicationTitle);
    this.errorData = errData;
    this.sensorNumber = sensorNum;
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Time", "Error", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);
    //lineChart.setBackgroundPaint(Color.red);
    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1200, 500));
    setContentPane(chartPanel);//from  w ww  . j  a v  a  2  s.com

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

}

From source file:com.spotlightppm.BarChart.java

public void createBarChart() {

    dataset.setValue(mouseData.size(), "Number of Presses", "Mouse");
    dataset.setValue(keyData.size(), "Number of Presses", "Key");
    String title = "Number of Mouse and Key Presses between " + start.toString() + " - " + end.toString();
    JFreeChart chart = ChartFactory.createBarChart(title, "Mouse/Key", "Number of Presses", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    try {/*www .  j  a v  a2s  .  c  om*/
        ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300);
    } catch (IOException ex) {
        Logger.getLogger(BarChart.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:org.softinica.maven.jmeter.report.analyser.AbstractGraphAnalyzer.java

protected void saveJpegChart(PageDefinition definition, JFreeChart chart) {
    try {//from ww  w  . j  a va  2 s  .  co  m
        ChartUtilities.saveChartAsJPEG(definition.getOutputFile(), chart, definition.getWidth(),
                definition.getHeight());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.marmoush.jann.chart.ChartImage.java

public void createJPEG() {
    try {// w w  w  . j av a2s  .c o  m
        File file = new File(path);
        ChartUtilities.saveChartAsJPEG(file, chart, width, height);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:overSession.CreateGraph.java

public CreateGraph(String applicationTitle, String chartTitle, LinkedList<LinkedList<String>> pData,
        int sensorNum) {
    super(applicationTitle);
    this.pressureData = pData;
    this.sensorNumber = sensorNum;
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Session",
            "Average Pressure Value (per session)", createDataset(), PlotOrientation.VERTICAL, true, true,
            false);/*from   ww w .j  ava  2s.c o m*/
    //lineChart.setBackgroundPaint(Color.red);
    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1200, 500));
    setContentPane(chartPanel);

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

}

From source file:SyntheticData.XYLineChart.java

public XYLineChart(String applicationTitle, String chartTitle, String xaxislabel, String yaxislabel,
        XYSeriesCollection dataset) throws IOException {

    super(applicationTitle);
    JFreeChart xylinechart = ChartFactory.createXYLineChart(chartTitle, xaxislabel, yaxislabel, dataset,
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel cpanel = new ChartPanel(xylinechart);
    cpanel.setPreferredSize(new java.awt.Dimension(500, 500));
    final XYPlot xyplot = xylinechart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    xyplot.setRenderer(renderer);//from  ww  w. j  a v a  2  s .  c  om
    setContentPane(cpanel);
    File saveImageFile = new File("" + applicationTitle + ".jpg");
    ChartUtilities.saveChartAsJPEG(saveImageFile, xylinechart, 1920, 1080);
}