KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > demos > AdvancedStaticChart


1 /*
2  *
3  * AdvancedStaticChart jchart2d
4  * Copyright (C) Achim Westermann, created on 10.12.2004, 13:48:55
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  * If you modify or optimize the code in a useful way please let me know.
21  * Achim.Westermann@gmx.de
22  *
23  */

24 package info.monitorenter.gui.chart.demos;
25
26 import info.monitorenter.gui.chart.AAxis;
27 import info.monitorenter.gui.chart.Chart2D;
28 import info.monitorenter.gui.chart.ITrace2D;
29 import info.monitorenter.gui.chart.axis.AxisLinear;
30 import info.monitorenter.gui.chart.labelformatters.LabelFormatterDate;
31 import info.monitorenter.gui.chart.traces.Trace2DSimple;
32
33 import java.awt.event.WindowAdapter JavaDoc;
34 import java.awt.event.WindowEvent JavaDoc;
35 import java.text.DateFormat JavaDoc;
36 import java.text.ParseException JavaDoc;
37 import java.text.SimpleDateFormat JavaDoc;
38
39 import javax.swing.JFrame JavaDoc;
40
41
42 /**
43  * Demonstrates advanced features of static charts in jchart2d.
44  * <p>
45  *
46  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
47  *
48  */

49 public final class AdvancedStaticChart {
50
51   /**
52    * Application startup hook.
53    * <p>
54    *
55    * @param args
56    * ignored
57    *
58    * @throws ParseException
59    * if sth. goes wrong.
60    *
61    */

62   public static void main(final String JavaDoc[] args) throws ParseException JavaDoc {
63     // Create a chart:
64
Chart2D chart = new Chart2D();
65     // Create an ITrace:
66
ITrace2D trace = new Trace2DSimple();
67     AAxis yAxis = new AxisLinear();
68     yAxis.setFormatter(new LabelFormatterDate(new SimpleDateFormat JavaDoc()));
69     chart.setAxisY(yAxis);
70     // Add all points, as it is static:
71
double high = DateFormat.getInstance().parse("01.08.05 18:00").getTime();
72     for (double i = 0; i < 200; i++) {
73       trace.addPoint(i, high);
74       high += 1000 * 50;
75
76     }
77     // Add the trace to the chart:
78
chart.addTrace(trace);
79
80     // Make it visible:
81
// Create a frame.
82
JFrame JavaDoc frame = new JFrame JavaDoc("AdvancedStaticChart");
83     // add the chart to the frame:
84
frame.getContentPane().add(chart);
85     frame.setSize(600, 600);
86     // Enable the termination button [cross on the upper right edge]:
87
frame.addWindowListener(new WindowAdapter JavaDoc() {
88       public void windowClosing(final WindowEvent JavaDoc e) {
89         System.exit(0);
90       }
91     });
92     frame.setVisible(true);
93   }
94
95   /**
96    * Utility constructor.
97    * <p>
98    */

99   private AdvancedStaticChart() {
100     super();
101   }
102 }
103
Popular Tags