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 PieChartDemo4 extends ApplicationFrame { 58 59 64 public PieChartDemo4(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 data.setValue("Seven", new Double (19.4)); 77 data.setValue("Eight", new Double (19.4)); 78 data.setValue("Nine", new Double (9.4)); 79 data.setValue("Ten", new Double (19.4)); 80 data.setValue("Eleven", new Double (9.4)); 81 data.setValue("Twelve", new Double (9.4)); 82 data.setValue("Thirteen", new Double (9.4)); 83 data.setValue("Fourteen", new Double (9.4)); 84 85 JFreeChart chart = ChartFactory.createPieChart( 87 "Pie Chart Demo 4", data, true, true, 91 false 92 ); 93 94 chart.setBackgroundPaint(Color.yellow); 96 PiePlot plot = (PiePlot) chart.getPlot(); 97 plot.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS); 98 plot.setNoDataMessage("No data available"); 99 plot.setItemLabelGenerator(new StandardPieItemLabelGenerator()); 100 plot.setSectionPaint(0, new Color (0xCC, 0xCC, 0xFF)); 101 plot.setSectionPaint(1, new Color (0xFF, 0xCC, 0xCC)); 102 plot.setSectionPaint(2, new Color (0xCC, 0xFF, 0xCC)); 103 plot.setSectionPaint(3, new Color (0xFF, 0x99, 0x99)); 104 plot.setSectionPaint(4, new Color (0x99, 0xFF, 0x99)); 105 plot.setSectionPaint(5, new Color (0x99, 0x99, 0xFF)); 106 107 plot.setSectionOutlinePaint(null); 108 plot.setSectionOutlinePaintListAutoFill(false); 109 110 ChartPanel chartPanel = new ChartPanel(chart); 112 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 113 setContentPane(chartPanel); 114 115 } 116 117 128 133 public static void main(String [] args) { 134 135 PieChartDemo4 demo = new PieChartDemo4("Pie Chart Demo 4"); 136 demo.pack(); 137 RefineryUtilities.centerFrameOnScreen(demo); 138 demo.setVisible(true); 139 140 } 141 142 } 143 | Popular Tags |