1 39 40 package org.jfree.chart.demo; 41 42 import java.awt.Color ; 43 44 import org.jfree.chart.ChartFactory; 45 import org.jfree.chart.ChartPanel; 46 import org.jfree.chart.JFreeChart; 47 import org.jfree.chart.plot.Pie3DPlot; 48 import org.jfree.data.DefaultPieDataset; 49 import org.jfree.data.PieDataset; 50 import org.jfree.ui.ApplicationFrame; 51 import org.jfree.ui.RefineryUtilities; 52 import org.jfree.util.Rotation; 53 54 60 public class Pie3DChartDemo1 extends ApplicationFrame { 61 62 67 public Pie3DChartDemo1(String title) { 68 69 super(title); 70 71 PieDataset dataset = createSampleDataset(); 73 74 JFreeChart chart = createChart(dataset); 76 77 ChartPanel chartPanel = new ChartPanel(chart); 79 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 80 setContentPane(chartPanel); 81 82 } 83 84 89 private PieDataset createSampleDataset() { 90 91 DefaultPieDataset result = new DefaultPieDataset(); 92 result.setValue("Java", new Double (43.2)); 93 result.setValue("Visual Basic", new Double (10.0)); 94 result.setValue("C/C++", new Double (17.5)); 95 result.setValue("PHP", new Double (32.5)); 96 result.setValue("Perl", new Double (0.0)); 97 return result; 98 99 } 100 101 112 119 private JFreeChart createChart(PieDataset dataset) { 120 121 JFreeChart chart = ChartFactory.createPie3DChart( 122 "Pie Chart 3D Demo 1", dataset, true, true, 126 false 127 ); 128 129 chart.setBackgroundPaint(Color.yellow); 131 Pie3DPlot plot = (Pie3DPlot) chart.getPlot(); 132 plot.setStartAngle(270); 133 plot.setDirection(Rotation.CLOCKWISE); 134 plot.setForegroundAlpha(0.5f); 135 plot.setNoDataMessage("No data to display"); 136 137 return chart; 138 139 } 140 141 146 public static void main(String [] args) { 147 148 Pie3DChartDemo1 demo = new Pie3DChartDemo1("Pie Chart 3D Demo 1"); 149 demo.pack(); 150 RefineryUtilities.centerFrameOnScreen(demo); 151 demo.setVisible(true); 152 153 } 154 155 } 156 | Popular Tags |