1 37 38 package org.jfree.chart.demo; 39 40 import java.awt.Graphics2D ; 41 import java.awt.event.ActionEvent ; 42 import java.awt.event.ActionListener ; 43 import java.awt.geom.Rectangle2D ; 44 import java.awt.image.BufferedImage ; 45 46 import javax.swing.Timer ; 47 48 import org.jfree.chart.ChartFactory; 49 import org.jfree.chart.JFreeChart; 50 import org.jfree.chart.plot.PlotOrientation; 51 import org.jfree.chart.plot.XYPlot; 52 import org.jfree.chart.renderer.XYDotRenderer; 53 import org.jfree.data.XYDataset; 54 55 62 public class ChartTiming2 implements ActionListener { 63 64 65 private boolean finished; 66 67 70 public ChartTiming2() { 71 } 72 73 76 public void run() { 77 78 this.finished = false; 79 80 XYDataset data = new SampleXYDataset2(1, 1440); 82 83 boolean withLegend = true; 85 JFreeChart chart = ChartFactory.createScatterPlot( 86 "Scatter plot timing", "X", "Y", 87 data, 88 PlotOrientation.VERTICAL, 89 withLegend, false, false 90 ); 91 92 XYPlot plot = chart.getXYPlot(); 93 plot.setRenderer(new XYDotRenderer()); 94 95 BufferedImage image = new BufferedImage (400, 300, BufferedImage.TYPE_INT_RGB); 96 Graphics2D g2 = image.createGraphics(); 97 Rectangle2D chartArea = new Rectangle2D.Double (0, 0, 400, 300); 98 99 Timer timer = new Timer (10000, this); 101 timer.setRepeats(false); 102 int count = 0; 103 timer.start(); 104 while (!finished) { 105 chart.draw(g2, chartArea, null); 106 System.out.println("Charts drawn..." + count); 107 if (!finished) { 108 count++; 109 } 110 } 111 System.out.println("DONE"); 112 113 } 114 115 120 public void actionPerformed(ActionEvent event) { 121 this.finished = true; 122 } 123 124 129 public static void main(String [] args) { 130 131 ChartTiming2 app = new ChartTiming2(); 132 app.run(); 133 134 } 135 136 } 137 | Popular Tags |