1 37 38 package org.jfree.chart.plot.junit; 39 40 import java.io.ByteArrayInputStream ; 41 import java.io.ByteArrayOutputStream ; 42 import java.io.ObjectInput ; 43 import java.io.ObjectInputStream ; 44 import java.io.ObjectOutput ; 45 import java.io.ObjectOutputStream ; 46 47 import junit.framework.Test; 48 import junit.framework.TestCase; 49 import junit.framework.TestSuite; 50 51 import org.jfree.chart.axis.AxisLocation; 52 import org.jfree.chart.axis.DateAxis; 53 import org.jfree.chart.axis.NumberAxis; 54 import org.jfree.chart.labels.TimeSeriesToolTipGenerator; 55 import org.jfree.chart.plot.CombinedDomainXYPlot; 56 import org.jfree.chart.plot.XYPlot; 57 import org.jfree.chart.renderer.StandardXYItemRenderer; 58 import org.jfree.chart.renderer.XYBarRenderer; 59 import org.jfree.chart.renderer.XYItemRenderer; 60 import org.jfree.data.IntervalXYDataset; 61 import org.jfree.data.XYDataset; 62 import org.jfree.data.time.Day; 63 import org.jfree.data.time.TimeSeries; 64 import org.jfree.data.time.TimeSeriesCollection; 65 import org.jfree.date.SerialDate; 66 67 72 public class CombinedXYPlotTests extends TestCase { 73 74 79 public static Test suite() { 80 return new TestSuite(CombinedXYPlotTests.class); 81 } 82 83 88 public CombinedXYPlotTests(String name) { 89 super(name); 90 } 91 92 95 public void testSerialization() { 96 97 CombinedDomainXYPlot p1 = new CombinedDomainXYPlot(new NumberAxis("Value")); 99 p1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT); 100 101 IntervalXYDataset data1 = createDataset1(); 103 XYItemRenderer renderer1 = new XYBarRenderer(0.20); 104 renderer1.setToolTipGenerator(new TimeSeriesToolTipGenerator("d-MMM-yyyy", "0,000.0")); 105 XYPlot subplot1 = new XYPlot(data1, new DateAxis("Date"), null, renderer1); 106 107 XYDataset data2 = this.createDataset2(); 109 XYItemRenderer renderer2 = new StandardXYItemRenderer(); 110 renderer2.setToolTipGenerator(new TimeSeriesToolTipGenerator("d-MMM-yyyy", "0,000.0")); 111 XYPlot subplot2 = new XYPlot(data2, new DateAxis("Date"), null, renderer2); 112 113 p1.add(subplot1, 1); 115 p1.add(subplot2, 1); 116 117 CombinedDomainXYPlot p2 = null; 118 119 try { 120 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 121 ObjectOutput out = new ObjectOutputStream (buffer); 122 out.writeObject(p1); 123 out.close(); 124 125 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 126 p2 = (CombinedDomainXYPlot) in.readObject(); 127 in.close(); 128 } 129 catch (Exception e) { 130 e.printStackTrace(); 131 } 132 assertEquals(p1, p2); 133 134 } 135 136 141 private IntervalXYDataset createDataset1() { 142 143 TimeSeries series1 = new TimeSeries("Series 1", Day.class); 145 series1.add(new Day(1, SerialDate.MARCH, 2002), 12353.3); 146 series1.add(new Day(2, SerialDate.MARCH, 2002), 13734.4); 147 series1.add(new Day(3, SerialDate.MARCH, 2002), 14525.3); 148 series1.add(new Day(4, SerialDate.MARCH, 2002), 13984.3); 149 series1.add(new Day(5, SerialDate.MARCH, 2002), 12999.4); 150 series1.add(new Day(6, SerialDate.MARCH, 2002), 14274.3); 151 series1.add(new Day(7, SerialDate.MARCH, 2002), 15943.5); 152 series1.add(new Day(8, SerialDate.MARCH, 2002), 14845.3); 153 series1.add(new Day(9, SerialDate.MARCH, 2002), 14645.4); 154 series1.add(new Day(10, SerialDate.MARCH, 2002), 16234.6); 155 series1.add(new Day(11, SerialDate.MARCH, 2002), 17232.3); 156 series1.add(new Day(12, SerialDate.MARCH, 2002), 14232.2); 157 series1.add(new Day(13, SerialDate.MARCH, 2002), 13102.2); 158 series1.add(new Day(14, SerialDate.MARCH, 2002), 14230.2); 159 series1.add(new Day(15, SerialDate.MARCH, 2002), 11235.2); 160 161 TimeSeriesCollection collection = new TimeSeriesCollection(series1); 162 collection.setDomainIsPointsInTime(false); return collection; 168 169 } 170 171 176 private XYDataset createDataset2() { 177 178 TimeSeries series2 = new TimeSeries("Series 2", Day.class); 180 181 series2.add(new Day(3, SerialDate.MARCH, 2002), 16853.2); 182 series2.add(new Day(4, SerialDate.MARCH, 2002), 19642.3); 183 series2.add(new Day(5, SerialDate.MARCH, 2002), 18253.5); 184 series2.add(new Day(6, SerialDate.MARCH, 2002), 15352.3); 185 series2.add(new Day(7, SerialDate.MARCH, 2002), 13532.0); 186 series2.add(new Day(8, SerialDate.MARCH, 2002), 12635.3); 187 series2.add(new Day(9, SerialDate.MARCH, 2002), 13998.2); 188 series2.add(new Day(10, SerialDate.MARCH, 2002), 11943.2); 189 series2.add(new Day(11, SerialDate.MARCH, 2002), 16943.9); 190 series2.add(new Day(12, SerialDate.MARCH, 2002), 17843.2); 191 series2.add(new Day(13, SerialDate.MARCH, 2002), 16495.3); 192 series2.add(new Day(14, SerialDate.MARCH, 2002), 17943.6); 193 series2.add(new Day(15, SerialDate.MARCH, 2002), 18500.7); 194 series2.add(new Day(16, SerialDate.MARCH, 2002), 19595.9); 195 196 return new TimeSeriesCollection(series2); 197 198 } 199 200 } 201 | Popular Tags |