1 37 38 package org.jfree.chart.demo; 39 40 import org.jfree.chart.ChartFactory; 41 import org.jfree.chart.ChartPanel; 42 import org.jfree.chart.JFreeChart; 43 import org.jfree.chart.Marker; 44 import org.jfree.data.time.Quarter; 45 import org.jfree.data.time.TimeSeries; 46 import org.jfree.data.time.TimeSeriesCollection; 47 import org.jfree.ui.ApplicationFrame; 48 import org.jfree.ui.RefineryUtilities; 49 50 56 public class TimeSeriesDemo2 extends ApplicationFrame { 57 58 63 public TimeSeriesDemo2(String title) { 64 65 super(title); 66 67 TimeSeries series = new TimeSeries("Quarterly Data", Quarter.class); 68 series.add(new Quarter(1, 2001), 500.2); 69 series.add(new Quarter(2, 2001), 694.1); 70 series.add(new Quarter(3, 2001), 734.4); 71 series.add(new Quarter(4, 2001), 453.2); 72 series.add(new Quarter(1, 2002), 500.2); 73 series.add(new Quarter(2, 2002), null); 74 series.add(new Quarter(3, 2002), 734.4); 75 series.add(new Quarter(4, 2002), 453.2); 76 TimeSeriesCollection dataset = new TimeSeriesCollection(series); 77 JFreeChart chart = ChartFactory.createTimeSeriesChart( 78 "Time Series Demo 2", 79 "Time", 80 "Value", 81 dataset, 82 true, 83 true, 84 false 85 ); 86 chart.getXYPlot().addRangeMarker(new Marker(550)); 87 Quarter q = new Quarter(2, 2002); 88 chart.getXYPlot().addDomainMarker(new Marker(q.getMiddleMillisecond())); 89 ChartPanel chartPanel = new ChartPanel(chart); 90 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 91 setContentPane(chartPanel); 92 93 } 94 95 106 111 public static void main(String [] args) { 112 113 TimeSeriesDemo2 demo = new TimeSeriesDemo2("Time Series Demo 2"); 114 demo.pack(); 115 RefineryUtilities.centerFrameOnScreen(demo); 116 demo.setVisible(true); 117 118 } 119 120 } 121 | Popular Tags |