1 39 40 package org.jfree.chart.demo; 41 42 import java.awt.BasicStroke ; 43 import java.awt.Color ; 44 import java.awt.Insets ; 45 46 import org.jfree.chart.ChartFactory; 47 import org.jfree.chart.ChartPanel; 48 import org.jfree.chart.JFreeChart; 49 import org.jfree.chart.Marker; 50 import org.jfree.chart.plot.XYPlot; 51 import org.jfree.chart.renderer.StandardXYItemRenderer; 52 import org.jfree.chart.renderer.XYItemRenderer; 53 import org.jfree.data.time.Day; 54 import org.jfree.data.time.Hour; 55 import org.jfree.data.time.TimeSeries; 56 import org.jfree.data.time.TimeSeriesCollection; 57 import org.jfree.ui.ApplicationFrame; 58 import org.jfree.ui.RefineryUtilities; 59 60 66 public class TimeSeriesDemo4 extends ApplicationFrame { 67 68 73 public TimeSeriesDemo4(String title) { 74 75 super(title); 76 TimeSeries series = new TimeSeries("Random Data", Hour.class); 77 Day today = new Day(); 78 series.add(new Hour(1, today), 500.2); 79 series.add(new Hour(2, today), 694.1); 80 series.add(new Hour(3, today), 734.4); 81 series.add(new Hour(4, today), 453.2); 82 series.add(new Hour(7, today), 500.2); 83 series.add(new Hour(8, today), null); 84 series.add(new Hour(12, today), 734.4); 85 series.add(new Hour(16, today), 453.2); 86 TimeSeriesCollection dataset = new TimeSeriesCollection(series); 87 88 String chartTitle = "\u20A2\u20A2\u20A2\u20A3\u20A4\u20A5\u20A6\u20A7\u20A8\u20A9\u20AA"; 90 JFreeChart chart = ChartFactory.createTimeSeriesChart( 91 chartTitle, 92 "Time", 93 "Value", 94 dataset, 95 true, 96 true, 97 false 98 ); 99 100 XYPlot plot = chart.getXYPlot(); 101 plot.setInsets(new Insets (0, 0, 0, 20)); 102 plot.addRangeMarker(new Marker(700, Color.blue, new BasicStroke (1.0f), Color.blue, 0.8f)); 103 plot.setBackgroundPaint(null); 104 plot.setBackgroundImage(JFreeChart.INFO.getLogo()); 105 XYItemRenderer renderer = plot.getRenderer(); 106 if (renderer instanceof StandardXYItemRenderer) { 107 StandardXYItemRenderer r = (StandardXYItemRenderer) renderer; 108 r.setPlotShapes(true); 109 r.setShapesFilled(true); 110 } 111 ChartPanel chartPanel = new ChartPanel(chart); 112 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 113 chartPanel.setMouseZoomable(true, false); 114 setContentPane(chartPanel); 115 116 } 117 118 129 134 public static void main(String [] args) { 135 136 TimeSeriesDemo4 demo = new TimeSeriesDemo4("Time Series Demo 4"); 137 demo.pack(); 138 RefineryUtilities.centerFrameOnScreen(demo); 139 demo.setVisible(true); 140 141 } 142 143 } 144 | Popular Tags |