1 38 39 package org.jfree.chart.demo; 40 41 import java.awt.Color ; 42 43 import org.jfree.chart.ChartFactory; 44 import org.jfree.chart.ChartPanel; 45 import org.jfree.chart.JFreeChart; 46 import org.jfree.chart.plot.PiePlot; 47 import org.jfree.data.CategoryDataset; 48 import org.jfree.data.DatasetUtilities; 49 import org.jfree.ui.ApplicationFrame; 50 import org.jfree.ui.RefineryUtilities; 51 52 58 public class MultiPieChartDemo extends ApplicationFrame { 59 60 65 public MultiPieChartDemo(String title) { 66 67 super(title); 68 69 double[][] data = new double[][] { 71 {3.0, 4.0, 3.0, 5.0}, 72 {5.0, 7.0, 6.0, 8.0}, 73 {5.0, 7.0, 3.0, 8.0}, 74 {1.0, 2.0, 3.0, 4.0}, 75 {2.0, 3.0, 2.0, 3.0} 76 }; 77 78 CategoryDataset dataset = DatasetUtilities.createCategoryDataset( 79 "Region ", 80 "Sales/Q", 81 data 82 ); 83 84 JFreeChart chart = ChartFactory.createPieChart( 86 "Multi Pie Chart", dataset, PiePlot.PER_ROW, 89 true, true, 91 false 92 ); 93 94 96 chart.setBackgroundPaint(Color.yellow); 97 PiePlot plot = (PiePlot) chart.getPlot(); 98 plot.setSectionLabelType(PiePlot.VALUE_AND_PERCENT_LABELS); 99 100 102 ChartPanel chartPanel = new ChartPanel(chart, true, true, true, false, true); 104 chartPanel.setPreferredSize(new java.awt.Dimension (600, 380)); 105 setContentPane(chartPanel); 106 107 } 108 109 120 125 public static void main(String [] args) { 126 127 MultiPieChartDemo demo = new MultiPieChartDemo("Multi Pie Chart Demo"); 128 demo.pack(); 129 RefineryUtilities.centerFrameOnScreen(demo); 130 demo.setVisible(true); 131 132 } 133 134 } 135 | Popular Tags |