KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > charts > PieChart3D


1 package dinamica.charts;
2
3 import dinamica.*;
4 import org.jfree.chart.*;
5 import org.jfree.data.general.*;
6 import org.jfree.util.*;
7 import org.jfree.chart.plot.*;
8 import org.jfree.chart.labels.*;
9
10 /**
11  * Chart plugin for Pie3D
12  * Last update: 20/july/2005
13  * @author Martin Cordova (dinamica@martincordova.com)
14  */

15 public class PieChart3D extends AbstractChartPlugin
16 {
17
18     /* (non-Javadoc)
19      * @see dinamica.AbstractChartPlugin#getChart(dinamica.Recordset, dinamica.Recordset)
20      */

21     public JFreeChart getChart(Recordset chartInfo, Recordset data)
22         throws Throwable JavaDoc
23     {
24
25         /* create a chart dataset using the data contained in the Recordset "data" */
26         DefaultPieDataset chartdata = new DefaultPieDataset();
27         data.top();
28         while (data.next())
29         {
30             String JavaDoc colx = (String JavaDoc)chartInfo.getValue("column-x");
31             String JavaDoc coly = (String JavaDoc)chartInfo.getValue("column-y");
32             Double JavaDoc value = new Double JavaDoc(String.valueOf(data.getValue(coly)));
33             
34             /* get label x */
35             String JavaDoc label = String.valueOf(data.getValue(colx));
36             
37             /* get value y */
38             if (value==null)
39                 value = new Double JavaDoc(0);
40             
41             /* feed chart dataset with values */
42             chartdata.setValue(label, value.doubleValue());
43         
44         }
45         
46         /* get chart params */
47         String JavaDoc title = (String JavaDoc)chartInfo.getValue("title");
48
49         /* create a chart */
50         JFreeChart chart = ChartFactory.createPieChart3D(title, chartdata, true, false, false);
51         
52         /* set pie decoration */
53         configurePlot( chart.getPlot() );
54
55         /* return chart */
56         return chart;
57
58     }
59
60     /**
61      * Configure chart decorations
62      */

63     public void configurePlot(Plot p)
64     {
65         PiePlot3D plot = (PiePlot3D) p;
66         plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}"));
67         plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
68         plot.setStartAngle(290D);
69         plot.setDirection(Rotation.CLOCKWISE);
70         plot.setForegroundAlpha(0.6F);
71     }
72     
73 }
74
Popular Tags