1 38 39 package org.jfree.chart.demo; 40 41 import java.awt.Graphics2D ; 42 import java.awt.event.ActionEvent ; 43 import java.awt.event.ActionListener ; 44 import java.awt.geom.Rectangle2D ; 45 import java.awt.image.BufferedImage ; 46 47 import javax.swing.Timer ; 48 49 import org.jfree.chart.ChartFactory; 50 import org.jfree.chart.JFreeChart; 51 import org.jfree.data.DefaultPieDataset; 52 53 60 public class ChartTiming1 implements ActionListener { 61 62 63 private boolean finished; 64 65 68 public ChartTiming1() { 69 } 70 71 74 public void run() { 75 this.finished = false; 76 77 DefaultPieDataset data = new DefaultPieDataset(); 79 data.setValue("One", new Double (10.3)); 80 data.setValue("Two", new Double (8.5)); 81 data.setValue("Three", new Double (3.9)); 82 data.setValue("Four", new Double (3.9)); 83 data.setValue("Five", new Double (3.9)); 84 data.setValue("Six", new Double (3.9)); 85 86 boolean withLegend = true; 88 JFreeChart chart = ChartFactory.createPieChart( 89 "Testing", 90 data, 91 withLegend, 92 true, 93 false 94 ); 95 96 BufferedImage image = new BufferedImage (400, 300, BufferedImage.TYPE_INT_RGB); 97 Graphics2D g2 = image.createGraphics(); 98 Rectangle2D chartArea = new Rectangle2D.Double (0, 0, 400, 300); 99 100 Timer timer = new Timer (10000, this); 102 timer.setRepeats(false); 103 int count = 0; 104 timer.start(); 105 while (!finished) { 106 chart.draw(g2, chartArea, null); 107 System.out.println("Charts drawn..." + count); 108 if (!finished) { 109 count++; 110 } 111 } 112 System.out.println("DONE"); 113 114 } 115 116 121 public void actionPerformed(ActionEvent event) { 122 this.finished = true; 123 } 124 125 130 public static void main(String [] args) { 131 132 ChartTiming1 app = new ChartTiming1(); 133 app.run(); 134 135 } 136 137 } 138 | Popular Tags |