1 38 39 package org.jfree.chart.demo; 40 41 import java.text.SimpleDateFormat ; 42 43 import org.jfree.chart.ChartFactory; 44 import org.jfree.chart.ChartPanel; 45 import org.jfree.chart.JFreeChart; 46 import org.jfree.chart.axis.DateAxis; 47 import org.jfree.chart.axis.ValueAxis; 48 import org.jfree.chart.plot.XYPlot; 49 import org.jfree.data.XYDataset; 50 import org.jfree.data.time.Month; 51 import org.jfree.data.time.TimeSeries; 52 import org.jfree.data.time.TimeSeriesCollection; 53 import org.jfree.ui.ApplicationFrame; 54 import org.jfree.ui.RefineryUtilities; 55 56 62 public class TimeSeriesDemo6 extends ApplicationFrame { 63 64 70 public TimeSeriesDemo6(String title) { 71 72 super(title); 73 XYDataset dataset = createDataset(); 74 JFreeChart chart = createChart(dataset); 75 ChartPanel chartPanel = new ChartPanel(chart); 76 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 77 setContentPane(chartPanel); 78 79 } 80 81 88 private JFreeChart createChart(XYDataset dataset) { 89 90 JFreeChart chart = ChartFactory.createTimeSeriesChart( 91 "Time Series Demo 6", 92 "Date", 93 "Value", 94 dataset, 95 true, 96 true, 97 false 98 ); 99 100 XYPlot plot = chart.getXYPlot(); 101 DateAxis axis = (DateAxis) plot.getDomainAxis(); 102 axis.setDateFormatOverride(new SimpleDateFormat ("MMM-yyyy")); 103 ValueAxis rangeAxis = plot.getRangeAxis(); 104 rangeAxis.setAutoRangeMinimumSize(1.0); 105 return chart; 106 107 } 108 109 120 125 public XYDataset createDataset() { 126 127 TimeSeries s1 = new TimeSeries("Series 1", Month.class); 128 s1.add(new Month(2, 2001), 0.0); 129 s1.add(new Month(3, 2001), 0.0); 130 s1.add(new Month(4, 2001), 0.0); 131 s1.add(new Month(5, 2001), 0.0); 132 s1.add(new Month(6, 2001), 0.0); 133 s1.add(new Month(7, 2001), 0.0); 134 s1.add(new Month(8, 2001), 0.0); 135 s1.add(new Month(9, 2001), 0.0); 136 s1.add(new Month(10, 2001), 0.0); 137 s1.add(new Month(11, 2001), 0.0); 138 s1.add(new Month(12, 2001), 0.0); 139 s1.add(new Month(1, 2002), 0.0); 140 s1.add(new Month(2, 2002), 0.0); 141 s1.add(new Month(3, 2002), 0.0); 142 s1.add(new Month(4, 2002), 0.0); 143 s1.add(new Month(5, 2002), 0.0); 144 s1.add(new Month(6, 2002), 0.0); 145 s1.add(new Month(7, 2002), 0.0); 146 147 TimeSeriesCollection dataset = new TimeSeriesCollection(); 148 dataset.addSeries(s1); 149 150 return dataset; 151 152 } 153 154 159 public static void main(String [] args) { 160 161 TimeSeriesDemo6 demo = new TimeSeriesDemo6("Time Series Demo 6"); 162 demo.pack(); 163 RefineryUtilities.centerFrameOnScreen(demo); 164 demo.setVisible(true); 165 166 } 167 168 } 169 | Popular Tags |