KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > PieChart


1 package com.calipso.reportgenerator.userinterface;
2
3 import org.jfree.ui.RefineryUtilities;
4 import javax.swing.*;
5 import java.awt.*;
6 import org.jfree.chart.JFreeChart;
7 import org.jfree.chart.ChartFactory;
8 import org.jfree.chart.ChartPanel;
9 import org.jfree.chart.plot.PiePlot3D;
10 import org.jfree.util.Rotation;
11 import org.jfree.data.general.DefaultPieDataset;
12
13
14 /**
15  * Representa un chart de tipo Torta
16  */

17 public class PieChart extends JFrame{
18
19     private double [] chartDataMatrix;
20     private String JavaDoc [] description;
21     private String JavaDoc tittle;
22     private boolean legend;
23     private boolean toolTips;
24
25     /**
26      * Inicializa un objeto de tipo Torta
27      * @param chartDataMatrix contiene los datos
28      * @param tittle contiene el titulo del chart
29      * @param description contiene las descripciones del chart
30      */

31     public PieChart(double [] chartDataMatrix, String JavaDoc [] description, String JavaDoc tittle, boolean legend, boolean toolTips){
32         this.chartDataMatrix = chartDataMatrix;
33         this.description = description;
34         this.tittle = tittle;
35         this.legend = legend;
36         this.toolTips = toolTips;
37         previewPieChart();
38         this.pack();
39         RefineryUtilities.centerFrameOnScreen(this);
40         this.setVisible(true);
41     }
42
43     /**
44      * Inicializa un conjunto de datos con las respectivas descripciones
45      * y crea el chart correspondiente
46      */

47     private void previewPieChart() {
48         DefaultPieDataset data = new DefaultPieDataset();
49
50         for(int i=0 ; i<chartDataMatrix.length ; i++) {
51             data.setValue(description[i], chartDataMatrix[i]);
52         }
53
54         // create the chart...
55
JFreeChart chart = ChartFactory.createPieChart3D(tittle, // chart title
56
data, // data
57
legend, // include legend
58
toolTips,
59                                                          false
60                                                          );
61
62         // set the background color for the chart...
63
chart.setBackgroundPaint(Color.white);
64         PiePlot3D plot = (PiePlot3D) chart.getPlot();
65         plot.setStartAngle(270);
66         plot.setDirection(Rotation.CLOCKWISE);
67         plot.setForegroundAlpha(0.5f);
68         // add the chart to a panel...
69
ChartPanel chartPanel = new ChartPanel(chart);
70         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(700, 500));
71         setContentPane(chartPanel);
72     }
73
74 }
75
Popular Tags