List of usage examples for org.jfree.chart ChartUtilities saveChartAsJPEG
public static void saveChartAsJPEG(File file, JFreeChart chart, int width, int height) throws IOException
From source file:utlis.HistogramPlot.java
public JFreeChart plotColorChart(ArrayList<int[]> histograms) { XYSeries xysRed = new XYSeries("Red"); XYSeries xysGreen = new XYSeries("Grean"); XYSeries xysBlue = new XYSeries("blue"); for (int i = 0; i < histograms.get(0).length; i++) { xysRed.add(i, histograms.get(0)[i]); xysBlue.add(i, histograms.get(2)[i]); xysGreen.add(i, histograms.get(1)[i]); }//ww w.j av a 2 s. c o m XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(xysRed); collection.addSeries(xysBlue); collection.addSeries(xysGreen); JFreeChart chart = ChartFactory.createXYLineChart("Histogram", "Color Value", "Pixel count", collection); try { ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300); } catch (IOException ex) { Logger.getLogger(HistogramPlot.class.getName()).log(Level.SEVERE, null, ex); } return chart; }
From source file:com.mycompany.task1.Chart.java
public void makeGroupedDataChart(int kolumna) { SortedSet sortedSet = calculation.getClassTypeCollection(); DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); TreeMap<Double, Integer> groupedMap; groupedMap = new TreeMap<Double, Integer>(); // mapa zawiera dane jednej kolumny dla jednej cechy nominalnej for (Object object : sortedSet) { Map<Double, Integer> mapa = calculation.histogramData(kolumna, object); prepareRangeMap(groupedMap, mapa); group(groupedMap, mapa);//from w w w .j a v a2 s . c om loadData(groupedMap, object, dataSet); } try { JFreeChart chart = displayChart(dataSet); ChartUtilities.saveChartAsJPEG(new File("GroupedData.jpg"), chart, 1000, 700); } catch (IOException ex) { Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.main.controller.ChartDIG.java
public File generatePieChart() throws Exception { DefaultPieDataset dataset = new DefaultPieDataset(); for (String arrayList1 : arrayList) { dataset.setValue(arrayList1, Double.parseDouble(arrayList1)); }// w ww.j a va2 s .com JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title dataset, // data true, // include legend true, false); File pieChart = new File("chart/" + chartTitle + ".jpeg"); ChartUtilities.saveChartAsJPEG(pieChart, chart, width, height); return pieChart; }
From source file:co.udea.edu.proyectointegrador.gr11.parqueaderoapp.domain.stadistics.graphics.implement.GraficaTest.java
/** * Test of createBarChartToVehicleType method, of class Grafica. */// ww w .j ava 2 s. c o m @Test public void testCreateBarChartToVehicleType() 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.createBarChartToVehicleType(controller.getEstadisticasByTipoVehiculo(startD, endD)); ChartUtilities.saveChartAsJPEG(new File("D:\\chart4.JPG"), chart, 200, 300); }
From source file:cachedataanalysis.FlowCacheGroup.java
public XYSeries exportReportChart() throws IOException { ArrayList<XYSeries> series = new ArrayList<XYSeries>(); for (FlowCache cache : caches) { series.add(cache.exportReportChart()); }//from ww w . ja va2 s .c om XYSeriesCollection data = new XYSeriesCollection(); for (XYSeries s : series) { data.addSeries(s); } JFreeChart chart = ChartFactory.createXYLineChart("Performance by Size", "Second", "Hit Rate", data); ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitRateComp" + size + ".jpg"), chart, 1500, 900); return series.get(series.size() / 2 + 1); }
From source file:app.utils.ImageUtilities.java
public static void saveHistogramToFile(JFreeChart chart) { try {//from w w w .j a va2 s . com File chartFile = new File(DEFAULT_FILE_SAVE_PATH + "histogram" + "." + DEFAULT_FILE_EXTENSION); ChartUtilities.saveChartAsJPEG(chartFile, chart, 400, 250); } catch (IOException ioe) { LOG.error("Error while saving chart to file.\n" + ioe.getMessage()); } }
From source file:br.com.ant.system.util.ChartUtil.java
public void createTempoTotalExecucao(Set<EstatisticaColetor> estatisticas) { // Create a simple XY chart XYSeries series = new XYSeries("Formiga"); JFrame frame = new JFrame(); for (EstatisticaColetor e : estatisticas) { series.add(e.getId(), e.getTempoExecucao()); }/*from ww w .j a va 2s. co m*/ // Add the series to your data set XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart("Tempo total de Execuo", "Execuo", "Tempo (ms)", dataset, PlotOrientation.VERTICAL, true, true, false); frame.getContentPane().add(new ChartPanel(chart)); frame.setPreferredSize(new Dimension(600, 600)); frame.setMinimumSize(new Dimension(600, 600)); frame.setMaximumSize(new Dimension(600, 600)); frame.setVisible(true); try { ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:sipl.recursos.Graficar.java
public void Danhos(int[] values, int[] fecha, int n, String direccion, String tiempo, String titulo) { try {/*from w w w . ja v a2 s . c om*/ DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int j = 0; j < n; j++) { dataset.addValue(values[j], "Cantidad de Daos", "" + fecha[j]); } JFreeChart chart = ChartFactory.createLineChart(titulo, tiempo, "Cantidad", dataset, PlotOrientation.VERTICAL, true, true, true); try { ChartUtilities.saveChartAsJPEG(new File(direccion), chart, 700, 500); } catch (IOException e) { System.out.println("Error al abrir el archivo"); } } catch (Exception e) { System.out.println(e); } }
From source file:graficos.GenerarGraficoFinanciero.java
public void crear() { try {/*from ww w . j ava 2s. com*/ Dba db = new Dba(pathdb); db.conectar(); String sql = "select IdCategoria, Nombre from Categoria"; db.prepare(sql); db.query.execute(); ResultSet rs = db.query.getResultSet(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String fechai = periodo.substring(0, 10) + " 00:00:00"; String fechaf = periodo.substring(13, 23) + " 00:00:00"; while (rs.next()) { String sql1 = "select Monto from PagoCliente join FichaCliente on PagoCliente.IdFichaCliente=FichaCliente.IdFichaCliente" + " join Reservacion on Reservacion.IdReservacion=FichaCliente.IdReservacion join Habitacion on Reservacion.IdHabitacion=" + "Habitacion.IdHabitacion where Habitacion.IdCategoria=" + rs.getInt(1) + " and FichaCliente.FechaSalida>='" + fechai + "' and" + " FichaCliente.FechaSalida<='" + fechaf + "'"; db.prepare(sql1); db.query.execute(); ResultSet rs1 = db.query.getResultSet(); Double monto = 0.0; while (rs1.next()) { monto += rs1.getDouble(1); } dataset.setValue(monto, "Ingresos", rs.getString(2)); } JFreeChart chart = ChartFactory.createBarChart3D( "Comparacin de Ingresos por Categora\nPeriodo:" + periodo, "Categora", "Ingresos", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); // Get the Plot object for a bar graph p.setBackgroundPaint(Color.black); 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) { } }
From source file:org.no_ip.xeps.jntpplot.Plotter.java
public void chart() { DefaultCategoryDataset statsDataset = new DefaultCategoryDataset(); System.out.println(stats);//from w w w. ja va 2 s. c om for (List<String> stat : stats) { for (int i = 1; i < statsLabels.size(); i++) { BigDecimal bd = new BigDecimal(stat.get(i)); statsDataset.addValue( //(Number) Long.valueOf(stat.get(i)), bd, (Comparable) statsLabels.get(i), (Comparable) stat.get(0)); } } // Chart bars if instructed to if (chartType == "bar") { JFreeChart barChartObject = ChartFactory.createBarChart(plotLabel, statsLabels.get(0), yLabel, statsDataset, PlotOrientation.VERTICAL, true, true, false); int width = 1280; int height = 1024; File barChart = new File(output); try { ChartUtilities.saveChartAsJPEG(barChart, barChartObject, width, height); } catch (IOException ex) { java.util.logging.Logger.getLogger(Plotter.class.getName()).log(Level.SEVERE, null, ex); logger.error("Failed to output linechart JPEG @ " + output + ": " + ex); } // Default to line charts } else { JFreeChart lineChartObject = ChartFactory.createLineChart(plotLabel, statsLabels.get(0), yLabel, statsDataset, PlotOrientation.VERTICAL, true, true, false); int width = 1280; int height = 1024; File lineChart = new File(output); try { ChartUtilities.saveChartAsJPEG(lineChart, lineChartObject, width, height); } catch (IOException ex) { java.util.logging.Logger.getLogger(Plotter.class.getName()).log(Level.SEVERE, null, ex); logger.error("Failed to output linechart JPEG @ " + output + ": " + ex); } } }