01: package com.calipso.reportgenerator.userinterface;
02:
03: import org.jfree.ui.RefineryUtilities;
04: import javax.swing.*;
05: import java.awt.*;
06: import org.jfree.chart.JFreeChart;
07: import org.jfree.chart.ChartFactory;
08: import org.jfree.chart.ChartPanel;
09: import org.jfree.chart.plot.PiePlot3D;
10: import org.jfree.util.Rotation;
11: import org.jfree.data.general.DefaultPieDataset;
12:
13: /**
14: * Representa un chart de tipo Torta
15: */
16: public class PieChart extends JFrame {
17:
18: private double[] chartDataMatrix;
19: private String[] description;
20: private String tittle;
21: private boolean legend;
22: private boolean toolTips;
23:
24: /**
25: * Inicializa un objeto de tipo Torta
26: * @param chartDataMatrix contiene los datos
27: * @param tittle contiene el titulo del chart
28: * @param description contiene las descripciones del chart
29: */
30: public PieChart(double[] chartDataMatrix, String[] description,
31: String 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, false);
59:
60: // set the background color for the chart...
61: chart.setBackgroundPaint(Color.white);
62: PiePlot3D plot = (PiePlot3D) chart.getPlot();
63: plot.setStartAngle(270);
64: plot.setDirection(Rotation.CLOCKWISE);
65: plot.setForegroundAlpha(0.5f);
66: // add the chart to a panel...
67: ChartPanel chartPanel = new ChartPanel(chart);
68: chartPanel.setPreferredSize(new java.awt.Dimension(700, 500));
69: setContentPane(chartPanel);
70: }
71:
72: }
|