1 37 38 package org.jfree.chart.demo; 39 40 import java.awt.Color ; 41 import java.awt.event.ActionEvent ; 42 import java.awt.event.ActionListener ; 43 44 import javax.swing.Timer ; 45 46 import org.jfree.chart.ChartFactory; 47 import org.jfree.chart.ChartPanel; 48 import org.jfree.chart.JFreeChart; 49 import org.jfree.chart.plot.Pie3DPlot; 50 import org.jfree.data.DefaultPieDataset; 51 import org.jfree.ui.ApplicationFrame; 52 import org.jfree.ui.RefineryUtilities; 53 import org.jfree.util.Rotation; 54 55 60 public class Pie3DChartDemo2 extends ApplicationFrame { 61 62 67 public Pie3DChartDemo2(String title) { 68 69 super(title); 70 71 DefaultPieDataset data = new DefaultPieDataset(); 73 data.setValue("Java", new Double (43.2)); 74 data.setValue("Visual Basic", new Double (10.0)); 75 data.setValue("C/C++", new Double (17.5)); 76 data.setValue("PHP", new Double (32.5)); 77 data.setValue("Perl", new Double (12.5)); 78 79 JFreeChart chart = ChartFactory.createPie3DChart("Pie Chart 3D Demo 2", data, true, true, 84 false 85 ); 86 87 chart.setBackgroundPaint(Color.yellow); 88 Pie3DPlot plot = (Pie3DPlot) chart.getPlot(); 89 plot.setStartAngle(270); 90 plot.setDirection(Rotation.ANTICLOCKWISE); 91 plot.setForegroundAlpha(0.60f); 92 plot.setInteriorGap(0.33); 93 ChartPanel chartPanel = new ChartPanel(chart); 95 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 96 setContentPane(chartPanel); 97 98 Rotator rotator = new Rotator(plot); 99 rotator.start(); 100 101 } 102 103 108 public static void main(String [] args) { 109 110 Pie3DChartDemo2 demo = new Pie3DChartDemo2("Pie Chart 3D Demo 2"); 111 demo.pack(); 112 RefineryUtilities.centerFrameOnScreen(demo); 113 demo.setVisible(true); 114 115 } 116 117 } 118 119 130 135 class Rotator extends Timer implements ActionListener { 136 137 138 private Pie3DPlot plot; 139 140 141 private int angle = 270; 142 143 148 Rotator(Pie3DPlot plot) { 149 super(100, null); 150 this.plot = plot; 151 addActionListener(this); 152 } 153 154 159 public void actionPerformed(ActionEvent event) { 160 this.plot.setStartAngle(angle); 161 this.angle = this.angle + 1; 162 if (this.angle == 360) { 163 this.angle = 0; 164 } 165 } 166 167 } 168 | Popular Tags |