source: ether_eccad/trunk/ECCAD_INTERFACE/WEB-INF/src/org/medias/eccad/metier/test/TimeSeriesDemo.java @ 70

Last change on this file since 70 was 70, checked in by cbipsl, 14 years ago

maj eccad V3.2

  • Property svn:executable set to *
File size: 6.8 KB
Line 
1package org.medias.eccad.metier.test;
2/* ===========================================================
3 * JFreeChart : a free chart library for the Java(tm) platform
4 * ===========================================================
5 *
6 * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
7 *
8 * Project Info:  http://www.jfree.org/jfreechart/index.html
9 *
10 * This library is free software; you can redistribute it and/or modify it under the terms
11 * of the GNU Lesser General Public License as published by the Free Software Foundation;
12 * either version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License along with this
19 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
21 *
22 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23 * in the United States and other countries.]
24 *
25 * -------------------
26 * TimeSeriesDemo.java
27 * -------------------
28 * (C) Copyright 2002-2004, by Object Refinery Limited and Contributors.
29 *
30 * Original Author:  David Gilbert (for Object Refinery Limited);
31 * Contributor(s):   -;
32 *
33 * $Id: TimeSeriesDemo.java,v 1.1 2005/04/28 16:29:16 harrym_nu Exp $
34 *
35 * Changes
36 * -------
37 * 08-Apr-2002 : Version 1 (DG);
38 * 25-Jun-2002 : Removed unnecessary import (DG);
39 *
40 */
41
42
43import java.awt.Color;
44import java.text.SimpleDateFormat;
45
46import org.jfree.chart.ChartFactory;
47import org.jfree.chart.ChartPanel;
48import org.jfree.chart.JFreeChart;
49import org.jfree.chart.axis.DateAxis;
50import org.jfree.chart.plot.XYPlot;
51import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
52import org.jfree.chart.renderer.xy.XYItemRenderer;
53import org.jfree.data.time.TimeSeriesCollection;
54import org.jfree.data.xy.XYDataset;
55import org.jfree.ui.ApplicationFrame;
56import org.jfree.ui.RefineryUtilities;
57
58/**
59 * An example of a time series chart.  For the most part, default settings are used, except that
60 * the renderer is modified to show filled shapes (as well as lines) at each data point.
61 *
62 * @author David Gilbert
63 */
64public class TimeSeriesDemo extends ApplicationFrame {
65
66    /**
67         *
68         */
69        private static final long serialVersionUID = 1L;
70
71        /**
72     * A demonstration application showing how to create a simple time series chart.  This
73     * example uses monthly data.
74     *
75     * @param title  the frame title.
76     */
77    public TimeSeriesDemo(String title) {
78       
79        super(title);
80        XYDataset dataset = createDataset();
81        JFreeChart chart = createChart(dataset);
82        ChartPanel chartPanel = new ChartPanel(chart);
83        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
84        chartPanel.setMouseZoomable(true, false);
85        setContentPane(chartPanel);
86
87    }
88
89    /**
90     * Creates a chart.
91     *
92     * @param dataset  a dataset.
93     *
94     * @return A chart.
95     */
96    private JFreeChart createChart(XYDataset dataset) {
97
98        JFreeChart chart = ChartFactory.createTimeSeriesChart(
99            "Legal & General Unit Trust Prices",
100            "Date", "Price Per Unit",
101            dataset,
102            true,
103            true,
104            false
105        );
106
107        chart.setBackgroundPaint(Color.white);
108
109        //StandardLegen sl = (StandardLegend) chart.getLegend();
110        //sl.setDisplaySeriesShapes(true);
111
112        XYPlot plot = chart.getXYPlot();
113        plot.setBackgroundPaint(Color.lightGray);
114        plot.setDomainGridlinePaint(Color.white);
115        plot.setRangeGridlinePaint(Color.white);
116        //plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
117        plot.setDomainCrosshairVisible(true);
118        plot.setRangeCrosshairVisible(true);
119       
120        XYItemRenderer renderer = plot.getRenderer();
121        if (renderer instanceof StandardXYItemRenderer) {
122//            StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
123            //rr.setPlotShapes(true);
124//            rr.setShapesFilled(true);
125//            rr.setItemLabelsVisible(true);
126        }
127       
128        DateAxis axis = (DateAxis) plot.getDomainAxis();
129        axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
130       
131        return chart;
132
133    }
134   
135    // ****************************************************************************
136    // * JFREECHART DEVELOPER GUIDE                                               *
137    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
138    // * to purchase from Object Refinery Limited:                                *
139    // *                                                                          *
140    // * http://www.object-refinery.com/jfreechart/guide.html                     *
141    // *                                                                          *
142    // * Sales are used to provide funding for the JFreeChart project - please    *
143    // * support us so that we can continue developing free software.             *
144    // ****************************************************************************
145   
146    /**
147     * Creates a dataset, consisting of two series of monthly data.
148     *
149     * @return the dataset.
150     */
151    private XYDataset createDataset() {
152
153//        TimeSeries s1 = new TimeSeries("L&G European Index Trust", Day.class);
154//        s1.add(new Day(2, 1, 2001), 181.8);
155//        s1.add(new Day(3, 1, 2001), 167.3);
156//        s1.add(new Day(4, 1, 2001), 153.8);
157//        s1.add(new Day(5, 1, 2001), 167.6);
158//        s1.add(new Day(6, 1, 2001), 158.8);
159//        s1.add(new Day(7, 1, 2001), 148.3);
160//        s1.add(new Day(8, 1, 2001), 153.9);
161//        s1.add(new Day(9, 1, 2001), 142.7);
162//        s1.add(new Day(10, 1, 2001), 123.2);
163//        s1.add(new Day(11, 1, 2001), 131.8);
164//        s1.add(new Day(12, 1, 2001), 139.6);
165//        s1.add(new Day(13, 1, 2001), 142.9);
166//        s1.add(new Day(14, 1, 2001), 138.7);
167//        s1.add(new Day(15, 1, 2001), 137.3);
168//        s1.add(new Day(16, 1, 2001), 143.9);
169//        s1.add(new Day(17, 1, 2001), 139.8);
170//        s1.add(new Day(18, 1, 2001), 137.0);
171//        s1.add(new Day(19, 1, 2001), 132.8);
172
173
174        TimeSeriesCollection dataset = new TimeSeriesCollection();
175//        dataset.addSeries(s1);
176
177//        dataset.setDomainIsPointsInTime(true);
178
179        return dataset;
180
181    }
182
183    /**
184     * Starting point for the demonstration application.
185     *
186     * @param args  ignored.
187     */
188    public static void main(String[] args) {
189
190       
191        TimeSeriesDemo demo = new TimeSeriesDemo("Time Series Demo 1");
192        demo.pack();
193        RefineryUtilities.centerFrameOnScreen(demo);
194        demo.setVisible(true);
195
196    }
197
198}
Note: See TracBrowser for help on using the repository browser.