01: /*
02: * Created on 09/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:
27: import net.sf.jasperreports.engine.JRDefaultScriptlet;
28: import net.sf.jasperreports.engine.JRScriptletException;
29:
30: import org.jfree.chart.ChartFactory;
31: import org.jfree.chart.JFreeChart;
32: import org.jfree.chart.plot.PiePlot3D;
33: import org.jfree.data.general.DefaultPieDataset;
34: import org.jfree.util.Rotation;
35:
36: import br.com.gfp.internationalization.ReportsMessages;
37:
38: /**
39: *
40: * @author Igor Regis da Silva Simoes
41: * @since 01/08/2005 08:28:39
42: */
43: public class PieChartTransactionChart extends JRDefaultScriptlet {
44:
45: DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
46:
47: private NumberFormat formater = NumberFormat.getCurrencyInstance();
48:
49: /**
50: *
51: */
52: @Override
53: public void afterReportInit() throws JRScriptletException {
54: JFreeChart jfreechart = ChartFactory.createPieChart3D(
55: ReportsMessages.getMessages().getString("PizzaTitle"),
56: defaultpiedataset, true, true, false);
57: PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot();
58: pieplot3d.setStartAngle(290D);
59: pieplot3d.setDirection(Rotation.CLOCKWISE);
60: pieplot3d.setForegroundAlpha(0.5F);
61: pieplot3d.setNoDataMessage(ReportsMessages.getMessages()
62: .getString("NoDataToDisplay"));
63:
64: this .setVariableValue("Chart", new JCommonDrawableRenderer(
65: jfreechart));
66: }
67:
68: /**
69: * Aqui nós pegamos os resultados do SQL e colocamos nas variáveis que vamos manipular
70: * @see net.sf.jasperreports.engine.JRDefaultScriptlet#afterDetailEval()
71: */
72: @Override
73: public void afterDetailEval() throws JRScriptletException {
74: double value = ((Double) this .getFieldValue("Soma"))
75: .doubleValue();
76: defaultpiedataset.setValue(this .getFieldValue("Nome")
77: .toString()
78: + "(" + formater.format(value) + ")", value < 0 ? value
79: * -1 : value);
80: }
81: }
|