Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Rita * @author Rui * @author Srgio */ import java.io.File; import java.io.IOException; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; public class Trabalho_1 { /** * @param args the command line arguments */ 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."); } } }