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 net.sf.jasperreports.engine.JRDefaultScriptlet;
26: import net.sf.jasperreports.engine.JRScriptletException;
27:
28: import org.jfree.chart.ChartFactory;
29: import org.jfree.chart.JFreeChart;
30: import org.jfree.chart.axis.CategoryAxis;
31: import org.jfree.chart.axis.CategoryLabelPositions;
32: import org.jfree.chart.plot.CategoryPlot;
33: import org.jfree.chart.plot.PlotOrientation;
34: import org.jfree.chart.renderer.category.BarRenderer;
35: import org.jfree.chart.renderer.category.CategoryItemRenderer;
36: import org.jfree.data.category.CategoryDataset;
37: import org.jfree.data.category.DefaultCategoryDataset;
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 BarrasTipoLancamento extends JRDefaultScriptlet {
47: private ReportsMessages messages = ReportsMessages.getMessages();
48:
49: private DefaultCategoryDataset lancamentos = new DefaultCategoryDataset();
50:
51: /**
52: *
53: */
54: @Override
55: public void afterReportInit() throws JRScriptletException {
56: CategoryDataset categorydataset = lancamentos;
57:
58: JFreeChart jfreechart = ChartFactory.createBarChart3D(messages
59: .getString("GrafBarrasTipoLancamentoTitle"), messages
60: .getString("Categoria"), messages.getString("Valor"),
61: categorydataset, PlotOrientation.VERTICAL, true, true,
62: false);
63: CategoryPlot categoryplot = jfreechart.getCategoryPlot();
64: CategoryAxis categoryaxis = categoryplot.getDomainAxis();
65: categoryaxis.setCategoryLabelPositions(CategoryLabelPositions
66: .createUpRotationLabelPositions(0.39269908169872414D));
67: CategoryItemRenderer categoryitemrenderer = categoryplot
68: .getRenderer();
69: categoryitemrenderer.setItemLabelsVisible(true);
70: BarRenderer barrenderer = (BarRenderer) categoryitemrenderer;
71: barrenderer.setMaximumBarWidth(0.050000000000000003D);
72:
73: this .setVariableValue("Chart", new JCommonDrawableRenderer(
74: jfreechart));
75: }
76:
77: /**
78: * Aqui nós pegamos os resultados do SQL e colocamos nas variáveis que vamos manipular
79: * @see net.sf.jasperreports.engine.JRDefaultScriptlet#afterDetailEval()
80: */
81: @Override
82: public void afterDetailEval() throws JRScriptletException {
83: double valor = ((Double) this .getFieldValue("Soma"))
84: .doubleValue();
85: if (valor < 0)
86: valor *= -1;
87:
88: lancamentos.addValue(valor, messages.getString("Mes"), this
89: .getFieldValue("Mes").toString()
90: + "-" + this .getFieldValue("Ano").toString());
91: }
92: }
|