01: /*
02: * Created on 02/08/2005
03: *
04: * Swing Components - visit http://sf.net/projects/gfd
05: *
06: * Copyright (C) 2004 Igor Regis da Silva Simões
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or (at your option) any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: *
22: */
23: package br.com.gfp.reports;
24:
25: import java.text.DecimalFormat;
26: import java.text.SimpleDateFormat;
27:
28: import net.sf.jasperreports.engine.JRDefaultScriptlet;
29: import net.sf.jasperreports.engine.JRScriptletException;
30:
31: import org.jfree.chart.ChartFactory;
32: import org.jfree.chart.JFreeChart;
33: import org.jfree.chart.labels.StandardXYToolTipGenerator;
34: import org.jfree.chart.renderer.xy.XYItemRenderer;
35: import org.jfree.data.time.TimeSeries;
36: import org.jfree.data.time.TimeSeriesCollection;
37: import org.jfree.data.time.Year;
38:
39: /**
40: *
41: * @author Igor Regis da Silva Simoes
42: * @since 02/08/2005 07:58:34
43: */
44: public class GrafDespesasXReceitasAnual extends JRDefaultScriptlet {
45: private TimeSeries despesas = new TimeSeries("Despesas", Year.class);
46:
47: private TimeSeries receitas = new TimeSeries("Receitas", Year.class);
48:
49: /**
50: *
51: */
52: @Override
53: public void afterReportInit() throws JRScriptletException {
54: TimeSeriesCollection timeseriesCollection = new TimeSeriesCollection();
55: timeseriesCollection.addSeries(despesas);
56: timeseriesCollection.addSeries(receitas);
57:
58: JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(
59: "Despesas X Receitas - Anual", "Ano", "Valor",
60: timeseriesCollection, true, true, false);
61: XYItemRenderer xyitemrenderer = jfreechart.getXYPlot()
62: .getRenderer();
63: StandardXYToolTipGenerator standardxytooltipgenerator = new StandardXYToolTipGenerator(
64: "{0}: ({1}, {2})", new SimpleDateFormat("dd-MM-yyyy"),
65: new DecimalFormat("0.00"));
66: xyitemrenderer.setToolTipGenerator(standardxytooltipgenerator);
67:
68: this .setVariableValue("Chart", new JCommonDrawableRenderer(
69: jfreechart));
70: }
71:
72: /**
73: * Aqui nós pegamos os resultados do SQL e colocamos nas variáveis que vamos manipular
74: * @see net.sf.jasperreports.engine.JRDefaultScriptlet#afterDetailEval()
75: */
76: @Override
77: public void afterDetailEval() throws JRScriptletException {
78: despesas.add(new Year(((Integer) this
79: .getFieldValue("anoDespesa")).intValue()), new Double(
80: ((Double) this .getFieldValue("valorDespesa"))
81: .doubleValue()
82: * -1));
83: receitas.add(new Year(((Integer) this
84: .getFieldValue("anoDespesa")).intValue()), new Double(
85: ((Double) this .getFieldValue("valorReceita"))
86: .doubleValue()));
87: }
88: }
|