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 import org.jfree.data.XYSeries; 55 import org.jfree.data.XYSeriesCollection; 56 57 64 public class ChartTiming3 implements ActionListener { 65 66 67 private boolean finished; 68 69 72 public ChartTiming3() { 73 } 74 75 78 public void run() { 79 80 this.finished = false; 81 82 XYSeries series = new XYSeries("Random Data", true); 84 for (int i = 0; i < 1440; i++) { 85 double x = Math.random(); 86 double y = Math.random(); 87 series.add(x, y); 88 } 89 XYDataset data = new XYSeriesCollection(series); 90 91 boolean withLegend = true; 93 JFreeChart chart = ChartFactory.createScatterPlot( 94 "Scatter plot timing", "X", "Y", 95 data, 96 PlotOrientation.VERTICAL, 97 withLegend, 98 false, 99 false 100 ); 101 102 XYPlot plot = chart.getXYPlot(); 103 plot.setRenderer(new XYDotRenderer()); 104 105 BufferedImage image = new BufferedImage (400, 300, BufferedImage.TYPE_INT_RGB); 106 Graphics2D g2 = image.createGraphics(); 107 Rectangle2D chartArea = new Rectangle2D.Double (0, 0, 400, 300); 108 109 Timer timer = new Timer (10000, this); 111 timer.setRepeats(false); 112 int count = 0; 113 timer.start(); 114 while (!finished) { 115 chart.draw(g2, chartArea, null); 116 System.out.println("Charts drawn..." + count); 117 if (!finished) { 118 count++; 119 } 120 } 121 System.out.println("DONE"); 122 123 } 124 125 130 public void actionPerformed(ActionEvent event) { 131 this.finished = true; 132 } 133 134 139 public static void main(String [] args) { 140 141 ChartTiming3 app = new ChartTiming3(); 142 app.run(); 143 144 } 145 146 } 147 | Popular Tags |