1 37 38 package org.jfree.chart.demo; 39 40 import org.jfree.chart.ChartPanel; 41 import org.jfree.chart.JFreeChart; 42 import org.jfree.chart.axis.DateAxis; 43 import org.jfree.chart.axis.NumberAxis; 44 import org.jfree.chart.axis.ValueAxis; 45 import org.jfree.chart.plot.XYPlot; 46 import org.jfree.chart.renderer.XYBarRenderer; 47 import org.jfree.chart.renderer.XYItemRenderer; 48 import org.jfree.data.XYDataset; 49 import org.jfree.data.time.Day; 50 import org.jfree.data.time.SimpleTimePeriod; 51 import org.jfree.data.time.TimePeriodValues; 52 import org.jfree.data.time.TimePeriodValuesCollection; 53 import org.jfree.ui.ApplicationFrame; 54 import org.jfree.ui.RefineryUtilities; 55 56 61 public class TimePeriodValuesDemo2 extends ApplicationFrame { 62 63 68 public TimePeriodValuesDemo2(String title) { 69 70 super(title); 71 72 XYDataset data1 = createDataset(); 73 XYItemRenderer renderer1 = new XYBarRenderer(); 74 75 DateAxis domainAxis = new DateAxis("Date"); 76 ValueAxis rangeAxis = new NumberAxis("Value"); 77 78 XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1); 79 80 JFreeChart chart = new JFreeChart("Time Period Values Demo", plot); 81 ChartPanel chartPanel = new ChartPanel(chart); 82 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 83 chartPanel.setMouseZoomable(true, false); 84 setContentPane(chartPanel); 85 86 } 87 88 99 104 public XYDataset createDataset() { 105 106 TimePeriodValues s1 = new TimePeriodValues("Series 1"); 107 Day d1 = new Day(); 108 Day d2 = (Day) d1.next(); 109 Day d3 = (Day) d2.next(); 110 Day d4 = (Day) d3.next(); 111 Day d5 = (Day) d4.next(); 112 Day d6 = (Day) d5.next(); 113 Day d7 = (Day) d6.next(); 114 115 s1.add(new SimpleTimePeriod(d6.getStart(), d6.getEnd()), 74.95); 116 s1.add(new SimpleTimePeriod(d1.getStart(), d2.getEnd()), 55.75); 117 s1.add(new SimpleTimePeriod(d7.getStart(), d7.getEnd()), 90.45); 118 s1.add(new SimpleTimePeriod(d3.getStart(), d5.getEnd()), 105.75); 119 120 TimePeriodValuesCollection dataset = new TimePeriodValuesCollection(); 121 dataset.addSeries(s1); 122 dataset.setDomainIsPointsInTime(false); 123 124 return dataset; 125 126 } 127 128 133 public static void main(String [] args) { 134 135 TimePeriodValuesDemo2 demo = new TimePeriodValuesDemo2("Time Period Values Demo 2"); 136 demo.pack(); 137 RefineryUtilities.centerFrameOnScreen(demo); 138 demo.setVisible(true); 139 140 } 141 142 } 143 | Popular Tags |