01: package dinamica.charts;
02:
03: import dinamica.*;
04: import org.jfree.chart.*;
05: import org.jfree.data.general.*;
06: import org.jfree.chart.plot.*;
07: import org.jfree.chart.labels.*;
08:
09: /**
10: * Chart plugin for Pie3D
11: * Last update: 20/july/2005
12: * @author Martin Cordova (dinamica@martincordova.com)
13: */
14: public class PieChart3D extends AbstractChartPlugin {
15:
16: /* (non-Javadoc)
17: * @see dinamica.AbstractChartPlugin#getChart(dinamica.Recordset, dinamica.Recordset)
18: */
19: public JFreeChart getChart(Recordset chartInfo, Recordset data)
20: throws Throwable {
21:
22: /* create a chart dataset using the data contained in the Recordset "data" */
23: DefaultPieDataset chartdata = new DefaultPieDataset();
24: data.top();
25: while (data.next()) {
26: String colx = (String) chartInfo.getValue("column-x");
27: String coly = (String) chartInfo.getValue("column-y");
28:
29: /* get label x */
30: String label = data.getString(colx);
31:
32: /* get value y */
33: if (data.isNull(coly))
34: chartdata.setValue(label, 0);
35: else
36: chartdata.setValue(label, data.getDouble(coly));
37:
38: }
39:
40: /* get chart params */
41: String title = (String) chartInfo.getValue("title");
42:
43: /* create a chart */
44: JFreeChart chart = ChartFactory.createPieChart3D(title,
45: chartdata, true, false, false);
46:
47: /* set pie decoration */
48: configurePlot(chart.getPlot());
49:
50: /* return chart */
51: return chart;
52:
53: }
54:
55: /**
56: * Configure chart decorations
57: */
58: public void configurePlot(Plot p) {
59: PiePlot3D plot = (PiePlot3D) p;
60: StandardPieSectionLabelGenerator splg = new StandardPieSectionLabelGenerator(
61: "{2}");
62: splg.getPercentFormat().setMinimumFractionDigits(2);
63: plot.setLabelGenerator(splg);
64: plot.setDepthFactor(0.1);
65: plot.setForegroundAlpha(0.7F);
66: }
67:
68: }
|