package br.dsc.upe.poli.banco;

import java.awt.Color;
import java.io.File;
import java.io.IOException;



import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis3D;
import org.jfree.chart.axis.NumberAxis3D;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.data.category.*;
import org.jfree.data.general.DatasetUtilities;


public class GeradorGrafico {
	
	
	public GeradorGrafico(){
		System.out.println("construiu gerador");
	}
	
	
	
	public String geracaoGraficoBarras(double[][] dados) throws IOException {
		 
	            CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Team ", "tatat", dados);

	            JFreeChart chart = null;
	            BarRenderer renderer3D = null;
	            CategoryPlot plot = null;


	            CategoryAxis3D categoryAxis = new CategoryAxis3D("País");
	            ValueAxis valueAxis = new NumberAxis3D("Taxa de Desemprego");
	            renderer3D = new BarRenderer3D();

	            plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer3D);
	            plot.setOrientation(PlotOrientation.VERTICAL);
	            chart = new JFreeChart("País X Desemprego", JFreeChart.DEFAULT_TITLE_FONT, 
	            plot, true);

	            chart.setBackgroundPaint(new Color(249, 231, 236));

	            
	                 ChartRenderingInfo info = new ChartRenderingInfo
	                (new StandardEntityCollection());

	                 File file1 = new File("F:/jspTeste/WebContent/testes/teste.png");
	                ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
	                return file1.getCanonicalPath();
	             
		
	            
		
	}
	
	public static void main(String args[]){
			GeradorGrafico geradorGrafico = new GeradorGrafico();
			

			try {
				double[][] data = new double[][]{{210, 300, 320},{200, 304, 201} };
				geradorGrafico.geracaoGraficoBarras(data);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}

	

}
