1 37 38 package org.jfree.chart.demo; 39 40 import java.awt.Color ; 41 42 import org.jfree.chart.ChartFactory; 43 import org.jfree.chart.ChartPanel; 44 import org.jfree.chart.JFreeChart; 45 import org.jfree.chart.labels.StandardPieItemLabelGenerator; 46 import org.jfree.chart.plot.PiePlot; 47 import org.jfree.data.DefaultPieDataset; 48 import org.jfree.ui.ApplicationFrame; 49 import org.jfree.ui.RefineryUtilities; 50 51 57 public class PieChartDemo2 extends ApplicationFrame { 58 59 64 public PieChartDemo2(String title) { 65 66 super(title); 67 68 DefaultPieDataset data = new DefaultPieDataset(); 70 data.setValue("One", new Double (43.2)); 71 data.setValue("Two", new Double (10.0)); 72 data.setValue("Three", new Double (27.5)); 73 data.setValue("Four", new Double (17.5)); 74 data.setValue("Five", new Double (11.0)); 75 data.setValue("Six", new Double (19.4)); 76 77 JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", data, true, true, 82 false 83 ); 84 85 chart.setBackgroundPaint(Color.yellow); 87 PiePlot plot = (PiePlot) chart.getPlot(); 88 plot.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS); 89 plot.setNoDataMessage("No data available"); 90 plot.setItemLabelGenerator(new StandardPieItemLabelGenerator()); 91 plot.setRadius(0.70); 92 plot.setExplodePercent(1, 1.00); 93 94 ChartPanel chartPanel = new ChartPanel(chart); 96 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 97 setContentPane(chartPanel); 98 99 } 100 101 112 117 public static void main(String [] args) { 118 119 PieChartDemo2 demo = new PieChartDemo2("Pie Chart Demo 2"); 120 demo.pack(); 121 RefineryUtilities.centerFrameOnScreen(demo); 122 demo.setVisible(true); 123 124 } 125 126 } 127 | Popular Tags |