1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
  6. *
  7. * Project Info: http://www.jfree.org/jfreechart/index.html
  8. *
  9. * This library is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  17. * License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this library; if not, write to the Free Software Foundation,
  21. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  24. * in the United States and other countries.]
  25. *
  26. * ----------------
  27. * XYPlotTests.java
  28. * ----------------
  29. * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
  30. *
  31. * Original Author: David Gilbert (for Object Refinery Limited);
  32. * Contributor(s): -;
  33. *
  34. * $Id: XYPlotTests.java,v 1.6 2005/02/25 09:40:36 mungady Exp $
  35. *
  36. * Changes
  37. * -------
  38. * 26-Mar-2003 : Version 1 (DG);
  39. * 22-Mar-2004 : Added new cloning test (DG);
  40. * 05-Oct-2004 : Strengthened test for clone independence (DG);
  41. */
  42. package org.jfree.chart.plot.junit;
  43. import java.awt.BasicStroke;
  44. import java.awt.Color;
  45. import java.awt.Stroke;
  46. import java.io.ByteArrayInputStream;
  47. import java.io.ByteArrayOutputStream;
  48. import java.io.ObjectInput;
  49. import java.io.ObjectInputStream;
  50. import java.io.ObjectOutput;
  51. import java.io.ObjectOutputStream;
  52. import junit.framework.Test;
  53. import junit.framework.TestCase;
  54. import junit.framework.TestSuite;
  55. import org.jfree.chart.ChartFactory;
  56. import org.jfree.chart.JFreeChart;
  57. import org.jfree.chart.LegendItemCollection;
  58. import org.jfree.chart.axis.AxisLocation;
  59. import org.jfree.chart.axis.DateAxis;
  60. import org.jfree.chart.axis.NumberAxis;
  61. import org.jfree.chart.labels.StandardXYToolTipGenerator;
  62. import org.jfree.chart.plot.PlotOrientation;
  63. import org.jfree.chart.plot.ValueMarker;
  64. import org.jfree.chart.plot.XYPlot;
  65. import org.jfree.chart.renderer.xy.DefaultXYItemRenderer;
  66. import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
  67. import org.jfree.chart.renderer.xy.XYBarRenderer;
  68. import org.jfree.chart.renderer.xy.XYItemRenderer;
  69. import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
  70. import org.jfree.data.time.Day;
  71. import org.jfree.data.time.TimeSeries;
  72. import org.jfree.data.time.TimeSeriesCollection;
  73. import org.jfree.data.xy.IntervalXYDataset;
  74. import org.jfree.data.xy.XYDataset;
  75. import org.jfree.data.xy.XYSeries;
  76. import org.jfree.data.xy.XYSeriesCollection;
  77. import org.jfree.date.MonthConstants;
  78. import org.jfree.ui.Layer;
  79. import org.jfree.ui.RectangleInsets;
  80. /**
  81. * Tests for the {@link XYPlot} class.
  82. */
  83. public class XYPlotTests extends TestCase {
  84. /**
  85. * Returns the tests as a test suite.
  86. *
  87. * @return The test suite.
  88. */
  89. public static Test suite() {
  90. return new TestSuite(XYPlotTests.class);
  91. }
  92. /**
  93. * Constructs a new set of tests.
  94. *
  95. * @param name the name of the tests.
  96. */
  97. public XYPlotTests(String name) {
  98. super(name);
  99. }
  100. /**
  101. * Added this test in response to a bug report.
  102. */
  103. public void testGetDatasetCount() {
  104. XYPlot plot = new XYPlot();
  105. assertEquals(0, plot.getDatasetCount());
  106. }
  107. /**
  108. * Test the equals() method.
  109. */
  110. public void testEquals() {
  111. XYPlot plot1 = new XYPlot();
  112. XYPlot plot2 = new XYPlot();
  113. assertTrue(plot1.equals(plot2));
  114. // orientation...
  115. plot1.setOrientation(PlotOrientation.HORIZONTAL);
  116. assertFalse(plot1.equals(plot2));
  117. plot2.setOrientation(PlotOrientation.HORIZONTAL);
  118. assertTrue(plot1.equals(plot2));
  119. // axisOffset...
  120. plot1.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));
  121. assertFalse(plot1.equals(plot2));
  122. plot2.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));
  123. assertTrue(plot1.equals(plot2));
  124. // domainAxis...
  125. plot1.setDomainAxis(new NumberAxis("Domain Axis"));
  126. assertFalse(plot1.equals(plot2));
  127. plot2.setDomainAxis(new NumberAxis("Domain Axis"));
  128. assertTrue(plot1.equals(plot2));
  129. // domainAxisLocation...
  130. plot1.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
  131. assertFalse(plot1.equals(plot2));
  132. plot2.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
  133. assertTrue(plot1.equals(plot2));
  134. // secondary DomainAxes...
  135. plot1.setDomainAxis(11, new NumberAxis("Secondary Domain Axis"));
  136. assertFalse(plot1.equals(plot2));
  137. plot2.setDomainAxis(11, new NumberAxis("Secondary Domain Axis"));
  138. assertTrue(plot1.equals(plot2));
  139. // secondary DomainAxisLocations...
  140. plot1.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
  141. assertFalse(plot1.equals(plot2));
  142. plot2.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
  143. assertTrue(plot1.equals(plot2));
  144. // rangeAxis...
  145. plot1.setRangeAxis(new NumberAxis("Range Axis"));
  146. assertFalse(plot1.equals(plot2));
  147. plot2.setRangeAxis(new NumberAxis("Range Axis"));
  148. assertTrue(plot1.equals(plot2));
  149. // rangeAxisLocation...
  150. plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
  151. assertFalse(plot1.equals(plot2));
  152. plot2.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
  153. assertTrue(plot1.equals(plot2));
  154. // secondary RangeAxes...
  155. plot1.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));
  156. assertFalse(plot1.equals(plot2));
  157. plot2.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));
  158. assertTrue(plot1.equals(plot2));
  159. // secondary RangeAxisLocations...
  160. plot1.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
  161. assertFalse(plot1.equals(plot2));
  162. plot2.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
  163. assertTrue(plot1.equals(plot2));
  164. // secondary DatasetDomainAxisMap...
  165. plot1.mapDatasetToDomainAxis(11, 11);
  166. assertFalse(plot1.equals(plot2));
  167. plot2.mapDatasetToDomainAxis(11, 11);
  168. assertTrue(plot1.equals(plot2));
  169. // secondaryDatasetRangeAxisMap...
  170. plot1.mapDatasetToRangeAxis(11, 11);
  171. assertFalse(plot1.equals(plot2));
  172. plot2.mapDatasetToRangeAxis(11, 11);
  173. assertTrue(plot1.equals(plot2));
  174. // renderer
  175. plot1.setRenderer(new DefaultXYItemRenderer());
  176. assertFalse(plot1.equals(plot2));
  177. plot2.setRenderer(new DefaultXYItemRenderer());
  178. assertTrue(plot1.equals(plot2));
  179. // secondary renderers
  180. plot1.setRenderer(11, new DefaultXYItemRenderer());
  181. assertFalse(plot1.equals(plot2));
  182. plot2.setRenderer(11, new DefaultXYItemRenderer());
  183. assertTrue(plot1.equals(plot2));
  184. // domainGridlinesVisible
  185. plot1.setDomainGridlinesVisible(false);
  186. assertFalse(plot1.equals(plot2));
  187. plot2.setDomainGridlinesVisible(false);
  188. assertTrue(plot1.equals(plot2));
  189. // domainGridlineStroke
  190. Stroke stroke = new BasicStroke(2.0f);
  191. plot1.setDomainGridlineStroke(stroke);
  192. assertFalse(plot1.equals(plot2));
  193. plot2.setDomainGridlineStroke(stroke);
  194. assertTrue(plot1.equals(plot2));
  195. // domainGridlinePaint
  196. plot1.setDomainGridlinePaint(Color.blue);
  197. assertFalse(plot1.equals(plot2));
  198. plot2.setDomainGridlinePaint(Color.blue);
  199. assertTrue(plot1.equals(plot2));
  200. // rangeGridlinesVisible
  201. plot1.setRangeGridlinesVisible(false);
  202. assertFalse(plot1.equals(plot2));
  203. plot2.setRangeGridlinesVisible(false);
  204. assertTrue(plot1.equals(plot2));
  205. // rangeGridlineStroke
  206. plot1.setRangeGridlineStroke(stroke);
  207. assertFalse(plot1.equals(plot2));
  208. plot2.setRangeGridlineStroke(stroke);
  209. assertTrue(plot1.equals(plot2));
  210. // rangeGridlinePaint
  211. plot1.setRangeGridlinePaint(Color.blue);
  212. assertFalse(plot1.equals(plot2));
  213. plot2.setRangeGridlinePaint(Color.blue);
  214. assertTrue(plot1.equals(plot2));
  215. // zeroRangeBaselineVisible
  216. plot1.setZeroRangeBaselineVisible(true);
  217. assertFalse(plot1.equals(plot2));
  218. plot2.setZeroRangeBaselineVisible(true);
  219. assertTrue(plot1.equals(plot2));
  220. // zeroRangeBaselineStroke
  221. plot1.setZeroRangeBaselineStroke(stroke);
  222. assertFalse(plot1.equals(plot2));
  223. plot2.setZeroRangeBaselineStroke(stroke);
  224. assertTrue(plot1.equals(plot2));
  225. // zeroRangeBaselinePaint
  226. plot1.setZeroRangeBaselinePaint(Color.blue);
  227. assertFalse(plot1.equals(plot2));
  228. plot2.setZeroRangeBaselinePaint(Color.blue);
  229. assertTrue(plot1.equals(plot2));
  230. // rangeCrosshairVisible
  231. plot1.setRangeCrosshairVisible(true);
  232. assertFalse(plot1.equals(plot2));
  233. plot2.setRangeCrosshairVisible(true);
  234. assertTrue(plot1.equals(plot2));
  235. // rangeCrosshairValue
  236. plot1.setRangeCrosshairValue(100.0);
  237. assertFalse(plot1.equals(plot2));
  238. plot2.setRangeCrosshairValue(100.0);
  239. assertTrue(plot1.equals(plot2));
  240. // rangeCrosshairStroke
  241. plot1.setRangeCrosshairStroke(stroke);
  242. assertFalse(plot1.equals(plot2));
  243. plot2.setRangeCrosshairStroke(stroke);
  244. assertTrue(plot1.equals(plot2));
  245. // rangeCrosshairPaint
  246. plot1.setRangeCrosshairPaint(Color.red);
  247. assertFalse(plot1.equals(plot2));
  248. plot2.setRangeCrosshairPaint(Color.red);
  249. assertTrue(plot1.equals(plot2));
  250. // rangeCrosshairLockedOnData
  251. plot1.setRangeCrosshairLockedOnData(false);
  252. assertFalse(plot1.equals(plot2));
  253. plot2.setRangeCrosshairLockedOnData(false);
  254. assertTrue(plot1.equals(plot2));
  255. // range markers
  256. plot1.addRangeMarker(new ValueMarker(4.0));
  257. assertFalse(plot1.equals(plot2));
  258. plot2.addRangeMarker(new ValueMarker(4.0));
  259. assertTrue(plot1.equals(plot2));
  260. // secondary range markers
  261. plot1.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);
  262. assertFalse(plot1.equals(plot2));
  263. plot2.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);
  264. assertTrue(plot1.equals(plot2));
  265. // weight
  266. plot1.setWeight(3);
  267. assertFalse(plot1.equals(plot2));
  268. plot2.setWeight(3);
  269. assertTrue(plot1.equals(plot2));
  270. }
  271. /**
  272. * Confirm that basic cloning works.
  273. */
  274. public void testCloning() {
  275. XYPlot p1 = new XYPlot();
  276. XYPlot p2 = null;
  277. try {
  278. p2 = (XYPlot) p1.clone();
  279. }
  280. catch (CloneNotSupportedException e) {
  281. e.printStackTrace();
  282. System.err.println("XYPlotTests.testCloning: failed to clone.");
  283. }
  284. assertTrue(p1 != p2);
  285. assertTrue(p1.getClass() == p2.getClass());
  286. assertTrue(p1.equals(p2));
  287. }
  288. /**
  289. * Tests cloning for a more complex plot.
  290. */
  291. public void testCloning2() {
  292. XYPlot p1 = new XYPlot(
  293. null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"),
  294. new StandardXYItemRenderer()
  295. );
  296. p1.setRangeAxis(1, new NumberAxis("Range Axis 2"));
  297. p1.setRenderer(1, new XYBarRenderer());
  298. XYPlot p2 = null;
  299. try {
  300. p2 = (XYPlot) p1.clone();
  301. }
  302. catch (CloneNotSupportedException e) {
  303. e.printStackTrace();
  304. System.err.println("Failed to clone.");
  305. }
  306. assertTrue(p1 != p2);
  307. assertTrue(p1.getClass() == p2.getClass());
  308. assertTrue(p1.equals(p2));
  309. }
  310. /**
  311. * Tests the independence of the clones.
  312. */
  313. public void testCloneIndependence() {
  314. XYPlot p1 = new XYPlot(
  315. null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"),
  316. new StandardXYItemRenderer()
  317. );
  318. p1.setDomainAxis(1, new NumberAxis("Domain Axis 2"));
  319. p1.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);
  320. p1.setRangeAxis(1, new NumberAxis("Range Axis 2"));
  321. p1.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT);
  322. p1.setRenderer(1, new XYBarRenderer());
  323. XYPlot p2 = null;
  324. try {
  325. p2 = (XYPlot) p1.clone();
  326. }
  327. catch (CloneNotSupportedException e) {
  328. e.printStackTrace();
  329. System.err.println("Failed to clone.");
  330. }
  331. assertTrue(p1.equals(p2));
  332. p1.getDomainAxis().setLabel("Label");
  333. assertFalse(p1.equals(p2));
  334. p2.getDomainAxis().setLabel("Label");
  335. assertTrue(p1.equals(p2));
  336. p1.getDomainAxis(1).setLabel("S1");
  337. assertFalse(p1.equals(p2));
  338. p2.getDomainAxis(1).setLabel("S1");
  339. assertTrue(p1.equals(p2));
  340. p1.setDomainAxisLocation(1, AxisLocation.TOP_OR_RIGHT);
  341. assertFalse(p1.equals(p2));
  342. p2.setDomainAxisLocation(1, AxisLocation.TOP_OR_RIGHT);
  343. assertTrue(p1.equals(p2));
  344. p1.mapDatasetToDomainAxis(2, 1);
  345. assertFalse(p1.equals(p2));
  346. p2.mapDatasetToDomainAxis(2, 1);
  347. assertTrue(p1.equals(p2));
  348. p1.getRangeAxis().setLabel("Label");
  349. assertFalse(p1.equals(p2));
  350. p2.getRangeAxis().setLabel("Label");
  351. assertTrue(p1.equals(p2));
  352. p1.getRangeAxis(1).setLabel("S1");
  353. assertFalse(p1.equals(p2));
  354. p2.getRangeAxis(1).setLabel("S1");
  355. assertTrue(p1.equals(p2));
  356. p1.setRangeAxisLocation(1, AxisLocation.TOP_OR_LEFT);
  357. assertFalse(p1.equals(p2));
  358. p2.setRangeAxisLocation(1, AxisLocation.TOP_OR_LEFT);
  359. assertTrue(p1.equals(p2));
  360. p1.mapDatasetToRangeAxis(2, 1);
  361. assertFalse(p1.equals(p2));
  362. p2.mapDatasetToRangeAxis(2, 1);
  363. assertTrue(p1.equals(p2));
  364. p1.getRenderer().setOutlinePaint(Color.cyan);
  365. assertFalse(p1.equals(p2));
  366. p2.getRenderer().setOutlinePaint(Color.cyan);
  367. assertTrue(p1.equals(p2));
  368. p1.getRenderer(1).setOutlinePaint(Color.red);
  369. assertFalse(p1.equals(p2));
  370. p2.getRenderer(1).setOutlinePaint(Color.red);
  371. assertTrue(p1.equals(p2));
  372. }
  373. /**
  374. * Setting a null renderer should be allowed, but is generating a null
  375. * pointer exception in 0.9.7.
  376. */
  377. public void testSetNullRenderer() {
  378. boolean failed = false;
  379. try {
  380. XYPlot plot = new XYPlot(
  381. null, new NumberAxis("X"), new NumberAxis("Y"), null
  382. );
  383. plot.setRenderer(null);
  384. }
  385. catch (Exception e) {
  386. failed = true;
  387. }
  388. assertTrue(!failed);
  389. }
  390. /**
  391. * Serialize an instance, restore it, and check for equality.
  392. */
  393. public void testSerialization1() {
  394. XYDataset data = new XYSeriesCollection();
  395. NumberAxis domainAxis = new NumberAxis("Domain");
  396. NumberAxis rangeAxis = new NumberAxis("Range");
  397. StandardXYItemRenderer renderer = new StandardXYItemRenderer();
  398. XYPlot p1 = new XYPlot(data, domainAxis, rangeAxis, renderer);
  399. XYPlot p2 = null;
  400. try {
  401. ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  402. ObjectOutput out = new ObjectOutputStream(buffer);
  403. out.writeObject(p1);
  404. out.close();
  405. ObjectInput in = new ObjectInputStream(
  406. new ByteArrayInputStream(buffer.toByteArray())
  407. );
  408. p2 = (XYPlot) in.readObject();
  409. in.close();
  410. }
  411. catch (Exception e) {
  412. System.out.println(e.toString());
  413. }
  414. assertEquals(p1, p2);
  415. }
  416. /**
  417. * Serialize an instance, restore it, and check for equality. This test
  418. * uses a {@link DateAxis} and a {@link StandardXYToolTipGenerator}.
  419. */
  420. public void testSerialization2() {
  421. IntervalXYDataset data1 = createDataset1();
  422. XYItemRenderer renderer1 = new XYBarRenderer(0.20);
  423. renderer1.setToolTipGenerator(
  424. StandardXYToolTipGenerator.getTimeSeriesInstance()
  425. );
  426. XYPlot p1 = new XYPlot(data1, new DateAxis("Date"), null, renderer1);
  427. XYPlot p2 = null;
  428. try {
  429. ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  430. ObjectOutput out = new ObjectOutputStream(buffer);
  431. out.writeObject(p1);
  432. out.close();
  433. ObjectInput in = new ObjectInputStream(
  434. new ByteArrayInputStream(buffer.toByteArray())
  435. );
  436. p2 = (XYPlot) in.readObject();
  437. in.close();
  438. }
  439. catch (Exception e) {
  440. System.out.println(e.toString());
  441. }
  442. assertEquals(p1, p2);
  443. }
  444. /**
  445. * Problem to reproduce a bug in serialization. The bug (first reported
  446. * against the {@link org.jfree.chart.plot.CategoryPlot} class) is a null
  447. * pointer exception that occurs when drawing a plot after deserialization.
  448. * It is caused by four temporary storage structures (axesAtTop,
  449. * axesAtBottom, axesAtLeft and axesAtRight - all initialized as empty
  450. * lists in the constructor) not being initialized by the readObject()
  451. * method following deserialization. This test has been written to
  452. * reproduce the bug (now fixed).
  453. */
  454. public void testSerialization3() {
  455. XYSeriesCollection dataset = new XYSeriesCollection();
  456. JFreeChart chart = ChartFactory.createXYLineChart(
  457. "Test Chart",
  458. "Domain Axis",
  459. "Range Axis",
  460. dataset,
  461. PlotOrientation.VERTICAL,
  462. true,
  463. true,
  464. false
  465. );
  466. JFreeChart chart2 = null;
  467. // serialize and deserialize the chart....
  468. try {
  469. ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  470. ObjectOutput out = new ObjectOutputStream(buffer);
  471. out.writeObject(chart);
  472. out.close();
  473. ObjectInput in = new ObjectInputStream(
  474. new ByteArrayInputStream(buffer.toByteArray())
  475. );
  476. chart2 = (JFreeChart) in.readObject();
  477. in.close();
  478. }
  479. catch (Exception e) {
  480. System.out.println(e.toString());
  481. }
  482. boolean passed = true;
  483. try {
  484. chart2.createBufferedImage(300, 200);
  485. }
  486. catch (Exception e) {
  487. passed = false;
  488. e.printStackTrace();
  489. }
  490. assertTrue(passed);
  491. }
  492. /**
  493. * Some checks for the getRendererForDataset() method.
  494. */
  495. public void testGetRendererForDataset() {
  496. XYDataset d0 = new XYSeriesCollection();
  497. XYDataset d1 = new XYSeriesCollection();
  498. XYDataset d2 = new XYSeriesCollection();
  499. XYDataset d3 = new XYSeriesCollection(); // not used by plot
  500. XYItemRenderer r0 = new XYLineAndShapeRenderer();
  501. XYItemRenderer r2 = new XYLineAndShapeRenderer();
  502. XYPlot plot = new XYPlot();
  503. plot.setDataset(0, d0);
  504. plot.setDataset(1, d1);
  505. plot.setDataset(2, d2);
  506. plot.setRenderer(0, r0);
  507. // no renderer 1
  508. plot.setRenderer(2, r2);
  509. assertEquals(r0, plot.getRendererForDataset(d0));
  510. assertEquals(r0, plot.getRendererForDataset(d1));
  511. assertEquals(r2, plot.getRendererForDataset(d2));
  512. assertEquals(null, plot.getRendererForDataset(d3));
  513. assertEquals(null, plot.getRendererForDataset(null));
  514. }
  515. /**
  516. * Some checks for the getLegendItems() method.
  517. */
  518. public void testGetLegendItems() {
  519. // check the case where there is a secondary dataset that doesn't
  520. // have a renderer (i.e. falls back to renderer 0)
  521. XYDataset d0 = createDataset1();
  522. XYDataset d1 = createDataset2();
  523. XYItemRenderer r0 = new XYLineAndShapeRenderer();
  524. XYPlot plot = new XYPlot();
  525. plot.setDataset(0, d0);
  526. plot.setDataset(1, d1);
  527. plot.setRenderer(0, r0);
  528. LegendItemCollection items = plot.getLegendItems();
  529. assertEquals(2, items.getItemCount());
  530. }
  531. /**
  532. * Creates a sample dataset.
  533. *
  534. * @return Series 1.
  535. */
  536. private IntervalXYDataset createDataset1() {
  537. // create dataset 1...
  538. TimeSeries series1 = new TimeSeries("Series 1", Day.class);
  539. series1.add(new Day(1, MonthConstants.MARCH, 2002), 12353.3);
  540. series1.add(new Day(2, MonthConstants.MARCH, 2002), 13734.4);
  541. series1.add(new Day(3, MonthConstants.MARCH, 2002), 14525.3);
  542. series1.add(new Day(4, MonthConstants.MARCH, 2002), 13984.3);
  543. series1.add(new Day(5, MonthConstants.MARCH, 2002), 12999.4);
  544. series1.add(new Day(6, MonthConstants.MARCH, 2002), 14274.3);
  545. series1.add(new Day(7, MonthConstants.MARCH, 2002), 15943.5);
  546. series1.add(new Day(8, MonthConstants.MARCH, 2002), 14845.3);
  547. series1.add(new Day(9, MonthConstants.MARCH, 2002), 14645.4);
  548. series1.add(new Day(10, MonthConstants.MARCH, 2002), 16234.6);
  549. series1.add(new Day(11, MonthConstants.MARCH, 2002), 17232.3);
  550. series1.add(new Day(12, MonthConstants.MARCH, 2002), 14232.2);
  551. series1.add(new Day(13, MonthConstants.MARCH, 2002), 13102.2);
  552. series1.add(new Day(14, MonthConstants.MARCH, 2002), 14230.2);
  553. series1.add(new Day(15, MonthConstants.MARCH, 2002), 11235.2);
  554. TimeSeriesCollection collection = new TimeSeriesCollection(series1);
  555. collection.setDomainIsPointsInTime(false);
  556. // this tells the time series collection that
  557. // we intend the data to represent time periods
  558. // NOT points in time. This is required when
  559. // determining the min/max values in the
  560. // dataset's domain.
  561. return collection;
  562. }
  563. /**
  564. * Creates a sample dataset.
  565. *
  566. * @return A sample dataset.
  567. */
  568. private XYDataset createDataset2() {
  569. // create dataset 1...
  570. XYSeries series = new XYSeries("Series 2");
  571. XYSeriesCollection collection = new XYSeriesCollection(series);
  572. return collection;
  573. }
  574. }