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 17 public class PieChart extends JFrame{ 18 19 private double [] chartDataMatrix; 20 private String [] description; 21 private String tittle; 22 private boolean legend; 23 private boolean toolTips; 24 25 31 public PieChart(double [] chartDataMatrix, String [] description, 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 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 JFreeChart chart = ChartFactory.createPieChart3D(tittle, data, legend, toolTips, 59 false 60 ); 61 62 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 ChartPanel chartPanel = new ChartPanel(chart); 70 chartPanel.setPreferredSize(new java.awt.Dimension (700, 500)); 71 setContentPane(chartPanel); 72 } 73 74 } 75 | Popular Tags |