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.NumberFormat;
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.Day;
36: import org.jfree.data.time.TimeSeries;
37: import org.jfree.data.time.TimeSeriesCollection;
38:
39: import br.com.gfp.internationalization.ReportsMessages;
40:
41: /**
42: *
43: * @author Igor Regis da Silva Simoes
44: * @since 02/08/2005 07:58:34
45: */
46: public class GrafEvolucaoLancamentosDiaria extends JRDefaultScriptlet {
47: private ReportsMessages messages = ReportsMessages.getMessages();
48:
49: private TimeSeries lancamentos = new TimeSeries(messages
50: .getString("GrafEvolucaoLancamentosDiariaLineLabel"),
51: Day.class);
52:
53: /**
54: *
55: */
56: @Override
57: public void afterReportInit() throws JRScriptletException {
58: TimeSeriesCollection timeseriesCollection = new TimeSeriesCollection();
59: timeseriesCollection.addSeries(lancamentos);
60:
61: JFreeChart jfreechart = ChartFactory
62: .createTimeSeriesChart(
63: messages
64: .getString("GrafEvolucaoLancamentosDiariaTitle"),
65: messages.getString("Day"), messages
66: .getString("Value"),
67: timeseriesCollection, true, true, false);
68: XYItemRenderer xyitemrenderer = jfreechart.getXYPlot()
69: .getRenderer();
70: StandardXYToolTipGenerator standardxytooltipgenerator = new StandardXYToolTipGenerator(
71: "{0}: ({1}, {2})", new SimpleDateFormat("dd-MM-yyyy"),
72: NumberFormat.getCurrencyInstance());
73: xyitemrenderer.setToolTipGenerator(standardxytooltipgenerator);
74:
75: this .setVariableValue("Chart", new JCommonDrawableRenderer(
76: jfreechart));
77: }
78:
79: /**
80: * Aqui nós pegamos os resultados do SQL e colocamos nas variáveis que vamos manipular
81: * @see net.sf.jasperreports.engine.JRDefaultScriptlet#afterDetailEval()
82: */
83: @Override
84: public void afterDetailEval() throws JRScriptletException {
85: double valor = ((Double) this .getFieldValue("Valor"))
86: .doubleValue();
87: if (valor < 0)
88: valor *= -1;
89:
90: lancamentos.add(new Day(((Integer) this .getFieldValue("Dia"))
91: .intValue(), ((Integer) this .getFieldValue("Mes"))
92: .intValue(), ((Integer) this .getFieldValue("Ano"))
93: .intValue()), valor);
94: }
95: }
|