1 42 43 package org.jfree.chart.demo; 44 45 import java.awt.Font ; 46 47 import javax.swing.JPanel ; 48 49 import org.jfree.chart.ChartFactory; 50 import org.jfree.chart.ChartPanel; 51 import org.jfree.chart.JFreeChart; 52 import org.jfree.chart.plot.PiePlot; 53 import org.jfree.data.general.DefaultPieDataset; 54 import org.jfree.data.general.PieDataset; 55 import org.jfree.ui.ApplicationFrame; 56 import org.jfree.ui.RefineryUtilities; 57 58 62 public class PieChartDemo1 extends ApplicationFrame { 63 64 69 public PieChartDemo1(String title) { 70 super(title); 71 setContentPane(createDemoPanel()); 72 } 73 74 79 private static PieDataset createDataset() { 80 DefaultPieDataset dataset = new DefaultPieDataset(); 81 dataset.setValue("One", new Double (43.2)); 82 dataset.setValue("Two", new Double (10.0)); 83 dataset.setValue("Three", new Double (27.5)); 84 dataset.setValue("Four", new Double (17.5)); 85 dataset.setValue("Five", new Double (11.0)); 86 dataset.setValue("Six", new Double (19.4)); 87 return dataset; 88 } 89 90 97 private static JFreeChart createChart(PieDataset dataset) { 98 99 JFreeChart chart = ChartFactory.createPieChart( 100 "Pie Chart Demo 1", dataset, true, true, 104 false 105 ); 106 107 PiePlot plot = (PiePlot) chart.getPlot(); 108 plot.setLabelFont(new Font ("SansSerif", Font.PLAIN, 12)); 109 plot.setNoDataMessage("No data available"); 110 plot.setCircular(false); 111 plot.setLabelGap(0.02); 112 return chart; 113 114 } 115 116 121 public static JPanel createDemoPanel() { 122 JFreeChart chart = createChart(createDataset()); 123 return new ChartPanel(chart); 124 } 125 126 131 public static void main(String [] args) { 132 133 PieChartDemo1 demo = new PieChartDemo1("Pie Chart Demo 1"); 134 demo.pack(); 135 RefineryUtilities.centerFrameOnScreen(demo); 136 demo.setVisible(true); 137 138 } 139 140 } 141 | Popular Tags |