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:kcse_2013_results.BarChartExample.java
public static void main(String[] args) { // Create a simple Bar chart DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(6, "Profit", "Jane"); dataset.setValue(7, "Profit", "Tom"); dataset.setValue(8, "Profit", "Jill"); dataset.setValue(5, "Profit", "John"); dataset.setValue(12, "Profit", "Fred"); JFreeChart chart = ChartFactory.createBarChart("Comparison between Salesman", "Salesman", "Profit", dataset, PlotOrientation.VERTICAL, false, true, false); final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final int width = screenSize.width; final int height = screenSize.height; try {/*w ww .ja v a 2 s. c o m*/ ChartUtilities.saveChartAsJPEG(new File("C:\\Users\\Wachira\\Desktop\\chart.jpg"), chart, width, height); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:chart.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 v a2s. 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.jpeg"); ChartUtilities.saveChartAsJPEG(pieChart3D, chart, width, height); }
From source file:History.PieChart_DB.java
public static void main(String[] args) throws Exception { String mobilebrands[] = { "IPhone 5s", "SamSung Grand", "MotoG", "Nokia Lumia" }; int statOfRepair = 0; java.util.Date now = new java.util.Date(); String adminDate = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate(); /* Create MySQL Database Connection */ Class.forName("com.mysql.jdbc.Driver"); Connection connect = ConnectDatabase.connectDb("win", "win016"); Statement statement = connect.createStatement(); ResultSet resultSet = statement .executeQuery("SELECT COUNT(transID) AS statRepair FROM `Transaction` WHERE dateTime LIKE \'" + adminDate + "%\' AND action LIKE 'Repair'"); DefaultPieDataset dataset = new DefaultPieDataset(); while (resultSet.next()) { dataset.setValue(resultSet.getString("statRepair"), Double.parseDouble(resultSet.getString("unit_sale"))); }/*from w ww . j a v a 2s . co m*/ JFreeChart chart = ChartFactory.createPieChart("History", // chart title dataset, // data true, // include legend true, false); int width = 560; /* Width of the image */ int height = 370; /* Height of the image */ File pieChart = new File("Pie_Chart.jpeg"); ChartUtilities.saveChartAsJPEG(pieChart, chart, width, height); }
From source file:Trabalho_1.java
/** * @param args the command line arguments *//*w w w.ja va 2 s . c o m*/ public static void main(String[] args) { // TODO code application logic here Ambiente n = new Ambiente(51, 51); n.inicializa(100, 30); XYSeries series = new XYSeries("Lobos"); XYSeries series1 = new XYSeries("Ovelhas"); XYSeries series2 = new XYSeries("Vegetacao"); for (int i = 0; i < 5000; i++) { n.iteracao(i); series.add(i, n.getLobos()); series1.add(i, n.getOvelhas()); series2.add(i, n.getVegetacao()); } // Add the series to your data set XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); dataset.addSeries(series1); dataset.addSeries(series2); XYSeriesCollection dataset2 = new XYSeriesCollection(); dataset2.addSeries(series); dataset2.addSeries(series1); // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart("Lobos, Ovelhas e Vegetacao", "Iteracoes", "Numero de Animais", dataset, PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); try { ChartUtilities.saveChartAsJPEG(new File("Grafico.jpg"), chart, 640, 480); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } // Generate the graph JFreeChart chart2 = ChartFactory.createXYLineChart("Lobos e ovelhas", "Iteracoes", "Numero de Animais", dataset2, PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); try { ChartUtilities.saveChartAsJPEG(new File("Grafico2.jpg"), chart2, 640, 480); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:carbon.plot.PlotTimeSeries.java
public static void PlotTS(int yr, double[] ppm, int years, String chartOutput) { TimeSeries carbon = new TimeSeries("Carbon"); for (int i = 0; i < years; i++) { carbon.add(new Year(yr + i), ppm[i]); }/*from w ww .j a v a 2s . com*/ TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(carbon); JFreeChart chart = ChartFactory.createTimeSeriesChart("Atmospheric CO2 concentration", "Year", "CO2 (ppm)", dataset, false, true, true); try { File plot = new File(chartOutput); ChartUtilities.saveChartAsJPEG(plot, chart, 500, 300); new DisplayImage(chartOutput); } catch (IOException e) { System.err.println("Problem creating chart."); } }
From source file:cachedataanalysis.ReportChartGenerator.java
public static void DrawXYLineChart(String chartName, String xAxis, String yAxis, ArrayList<XYSeries> series) throws IOException { XYSeriesCollection serCol = new XYSeriesCollection(); for (XYSeries _xys : series) { serCol.addSeries(_xys);/*from w w w.j a v a 2 s. co m*/ } JFreeChart hitRateStat = ChartFactory.createXYLineChart( "Hit Rate variatoion throughout recording in " + chartName, "Seconds", "HitRate", serCol, PlotOrientation.VERTICAL, true, true, false); ChartUtilities.saveChartAsJPEG(new File("report/" + chartName + ".jpg"), hitRateStat, 1500, 900); }
From source file:treegross.standsimulation.TgGrafik.java
public void saveToJPEG(String dir) { File fn = new File(jpgFilename); ChartUtilities ut = null; try {//from www . ja v a2 s .c om ut.saveChartAsJPEG(fn, jfreeChart, 600, 400); } catch (Exception e) { System.out.println(e); } }
From source file:utlis.HistogramPlot.java
public JFreeChart plotGrayChart(int[] histogram) { XYSeries xysBrightnes = new XYSeries("Brightnes"); for (int i = 0; i < histogram.length; i++) { xysBrightnes.add(i, histogram[i]); }//w w w . j a va 2 s . co m XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(xysBrightnes); 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:spminiproject.lab2.chart.Histogram2.java
private static JFreeChart createChart(IntervalXYDataset dataset, String x, String y) { JFreeChart chart = ChartFactory.createHistogram("Histogram", x, y, dataset, PlotOrientation.VERTICAL, true, true, false);/*from w w w. j a va2s. c o m*/ XYPlot plot = (XYPlot) chart.getPlot(); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); try { ChartUtilities.saveChartAsJPEG(new File("C:\\Users\\User\\Desktop\\histogram.jpg"), chart, 500, 475); } catch (IOException e) { System.out.println("Failed to open file"); } return chart; }
From source file:uk.co.bssd.reporting.chart.JpegChartWriter.java
@Override public void write(JFreeChart chart) { try {// ww w . ja v a2s. c om ChartUtilities.saveChartAsJPEG(this.file, chart, this.width, this.height); } catch (IOException e) { throw new IllegalStateException("Unable to save chart", e); } }