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.JFreeChart; 49 import org.jfree.chart.axis.NumberAxis; 50 import org.jfree.chart.plot.FastScatterPlot; 51 import org.jfree.chart.plot.Plot; 52 53 60 public class ChartTiming4 implements ActionListener { 61 62 63 private boolean finished; 64 65 66 private float[][] data = new float[2][1440]; 67 68 71 public ChartTiming4() { 72 } 73 74 77 public void run() { 78 79 this.finished = false; 80 81 populateData(); 83 84 Plot plot = new FastScatterPlot(this.data, new NumberAxis("X"), new NumberAxis("Y")); 86 JFreeChart chart = new JFreeChart( 87 "Fast Scatter Plot Timing", 88 JFreeChart.DEFAULT_TITLE_FONT, 89 plot, 90 true 91 ); 92 93 BufferedImage image = new BufferedImage (400, 300, BufferedImage.TYPE_INT_RGB); 94 Graphics2D g2 = image.createGraphics(); 95 Rectangle2D chartArea = new Rectangle2D.Double (0, 0, 400, 300); 96 97 Timer timer = new Timer (10000, this); 99 timer.setRepeats(false); 100 int count = 0; 101 timer.start(); 102 while (!finished) { 103 chart.draw(g2, chartArea, null); 104 System.out.println("Charts drawn..." + count); 105 if (!finished) { 106 count++; 107 } 108 } 109 System.out.println("DONE"); 110 111 } 112 113 118 public void actionPerformed(ActionEvent event) { 119 this.finished = true; 120 } 121 122 125 private void populateData() { 126 127 for (int i = 0; i < data[0].length; i++) { 128 129 float x = i; 130 data[0][i] = x; 131 data[1][i] = 100 + (2 * x) + (float) Math.random() * 1440; 132 } 133 134 } 135 136 141 public static void main(String [] args) { 142 143 ChartTiming4 app = new ChartTiming4(); 144 app.run(); 145 146 } 147 148 } 149 | Popular Tags |