1 40 41 package org.jfree.chart.demo; 42 43 import org.jfree.chart.ChartPanel; 44 import org.jfree.chart.JFreeChart; 45 import org.jfree.chart.axis.DateAxis; 46 import org.jfree.chart.axis.NumberAxis; 47 import org.jfree.chart.labels.TimeSeriesToolTipGenerator; 48 import org.jfree.chart.plot.CombinedRangeXYPlot; 49 import org.jfree.chart.plot.XYPlot; 50 import org.jfree.chart.renderer.StandardXYItemRenderer; 51 import org.jfree.chart.renderer.XYBarRenderer; 52 import org.jfree.chart.renderer.XYItemRenderer; 53 import org.jfree.data.IntervalXYDataset; 54 import org.jfree.data.XYDataset; 55 import org.jfree.data.time.Day; 56 import org.jfree.data.time.TimeSeries; 57 import org.jfree.data.time.TimeSeriesCollection; 58 import org.jfree.date.SerialDate; 59 import org.jfree.ui.ApplicationFrame; 60 import org.jfree.ui.RefineryUtilities; 61 62 68 public class CombinedXYPlotDemo2 extends ApplicationFrame { 69 70 75 public CombinedXYPlotDemo2(String title) { 76 77 super(title); 78 JFreeChart chart = createCombinedChart(); 79 ChartPanel panel = new ChartPanel(chart, true, true, true, false, true); 80 panel.setPreferredSize(new java.awt.Dimension (500, 270)); 81 setContentPane(panel); 82 83 } 84 85 90 private JFreeChart createCombinedChart() { 91 92 IntervalXYDataset data1 = createDataset1(); 94 XYItemRenderer renderer1 = new XYBarRenderer(0.20); 95 renderer1.setToolTipGenerator(new TimeSeriesToolTipGenerator("d-MMM-yyyy", "0,000.0")); 96 XYPlot subplot1 = new XYPlot(data1, new DateAxis("Date"), null, renderer1); 97 98 XYDataset data2 = createDataset2(); 100 XYItemRenderer renderer2 = new StandardXYItemRenderer(); 101 renderer2.setToolTipGenerator(new TimeSeriesToolTipGenerator("d-MMM-yyyy", "0,000.0")); 102 XYPlot subplot2 = new XYPlot(data2, new DateAxis("Date"), null, renderer2); 103 104 CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis("Value")); 106 107 plot.add(subplot1, 1); 109 plot.add(subplot2, 1); 110 111 return new JFreeChart("Combined (Range) XY Plot", 113 JFreeChart.DEFAULT_TITLE_FONT, plot, true); 114 115 } 116 117 128 133 private IntervalXYDataset createDataset1() { 134 135 TimeSeries series1 = new TimeSeries("Series 1", Day.class); 137 series1.add(new Day(1, SerialDate.MARCH, 2002), 12353.3); 138 series1.add(new Day(2, SerialDate.MARCH, 2002), 13734.4); 139 series1.add(new Day(3, SerialDate.MARCH, 2002), 14525.3); 140 series1.add(new Day(4, SerialDate.MARCH, 2002), 13984.3); 141 series1.add(new Day(5, SerialDate.MARCH, 2002), 12999.4); 142 series1.add(new Day(6, SerialDate.MARCH, 2002), 14274.3); 143 series1.add(new Day(7, SerialDate.MARCH, 2002), 15943.5); 144 series1.add(new Day(8, SerialDate.MARCH, 2002), 14845.3); 145 series1.add(new Day(9, SerialDate.MARCH, 2002), 14645.4); 146 series1.add(new Day(10, SerialDate.MARCH, 2002), 16234.6); 147 series1.add(new Day(11, SerialDate.MARCH, 2002), 17232.3); 148 series1.add(new Day(12, SerialDate.MARCH, 2002), 14232.2); 149 series1.add(new Day(13, SerialDate.MARCH, 2002), 13102.2); 150 series1.add(new Day(14, SerialDate.MARCH, 2002), 14230.2); 151 series1.add(new Day(15, SerialDate.MARCH, 2002), 11235.2); 152 153 TimeSeriesCollection collection = new TimeSeriesCollection(series1); 154 collection.setDomainIsPointsInTime(false); return collection; 160 161 } 162 163 168 private XYDataset createDataset2() { 169 170 TimeSeries series2 = new TimeSeries("Series 2", Day.class); 172 173 series2.add(new Day(3, SerialDate.MARCH, 2002), 16853.2); 174 series2.add(new Day(4, SerialDate.MARCH, 2002), 19642.3); 175 series2.add(new Day(5, SerialDate.MARCH, 2002), 18253.5); 176 series2.add(new Day(6, SerialDate.MARCH, 2002), 15352.3); 177 series2.add(new Day(7, SerialDate.MARCH, 2002), 13532.0); 178 series2.add(new Day(8, SerialDate.MARCH, 2002), 12635.3); 179 series2.add(new Day(9, SerialDate.MARCH, 2002), 13998.2); 180 series2.add(new Day(10, SerialDate.MARCH, 2002), 11943.2); 181 series2.add(new Day(11, SerialDate.MARCH, 2002), 16943.9); 182 series2.add(new Day(12, SerialDate.MARCH, 2002), 17843.2); 183 series2.add(new Day(13, SerialDate.MARCH, 2002), 16495.3); 184 series2.add(new Day(14, SerialDate.MARCH, 2002), 17943.6); 185 series2.add(new Day(15, SerialDate.MARCH, 2002), 18500.7); 186 series2.add(new Day(16, SerialDate.MARCH, 2002), 19595.9); 187 188 return new TimeSeriesCollection(series2); 189 190 } 191 192 197 public static void main(String [] args) { 198 199 CombinedXYPlotDemo2 demo = new CombinedXYPlotDemo2("Combined XY Plot Demo"); 200 demo.pack(); 201 RefineryUtilities.centerFrameOnScreen(demo); 202 demo.setVisible(true); 203 204 } 205 206 } 207 | Popular Tags |