KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * MinimalStaticChart.java of project jchart2d, a demonstration
3  * of the minimal code to set up a chart with static data.
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.Chart2D;
27 import info.monitorenter.gui.chart.ITrace2D;
28 import info.monitorenter.gui.chart.layout.ChartPanel;
29 import info.monitorenter.gui.chart.traces.Trace2DSimple;
30
31 import java.awt.BorderLayout JavaDoc;
32 import java.awt.Color JavaDoc;
33 import java.awt.event.WindowAdapter JavaDoc;
34 import java.awt.event.WindowEvent JavaDoc;
35
36 import javax.swing.JFrame JavaDoc;
37 import javax.swing.JPanel JavaDoc;
38
39 /**
40  * Title: AdvancedStaticChart
41  * <p>
42  *
43  * Description: A chart to test labels. This chart uses a
44  * <code>{@link info.monitorenter.gui.chart.labelformatters.LabelFormatterNumber}</code>
45  * that formats to whole integer numbers. No same labels should appear.
46  * <p>
47  *
48  * Copyright: sample code taken from http://jchart2d.sourceforge.net/usage.shtml
49  * <p>
50  *
51  * Company: Infotility
52  * <p>
53  *
54  * @author Achim Westermann (original)
55  *
56  * @author Martin Rojo (modified)
57  *
58  * @version $Revision: 1.1 $
59  */

60 public final class MinimalStaticChart extends JPanel JavaDoc {
61   /**
62    * Generated for <code>serialVersionUID</code>.
63    */

64   private static final long serialVersionUID = 3257009847668192306L;
65
66   /**
67    * Main entry.
68    * <p>
69    *
70    * @param args
71    * ignored.
72    */

73   public static void main(final String JavaDoc[] args) {
74     for (int i = 0; i < 1; i++) {
75       JFrame JavaDoc frame = new JFrame JavaDoc("SampleChart");
76       frame.getContentPane().add(new MinimalStaticChart());
77       frame.addWindowListener(new WindowAdapter JavaDoc() {
78         public void windowClosing(final WindowEvent JavaDoc e) {
79           System.exit(0);
80         }
81       });
82       frame.setSize(600, 600);
83       frame.setLocation(i % 3 * 200, i / 3 * 100);
84       frame.setVisible(true);
85     }
86   }
87
88   /**
89    * Defcon.
90    */

91   private MinimalStaticChart() {
92     this.setLayout(new BorderLayout JavaDoc());
93     Chart2D chart = new Chart2D();
94
95     // Create an ITrace:
96
// Note that dynamic charts need limited amount of values!!!
97
// ITrace2D trace = new Trace2DLtd(200);
98
// 3/11/-5 , let's try something else too:
99
ITrace2D trace = new Trace2DSimple();
100     trace.setColor(Color.RED);
101
102     // Add all points, as it is static:
103
double time = System.currentTimeMillis();
104     for (int i = 0; i < 100; i++) {
105       trace.addPoint(time + i, i * 1000);
106     }
107     // Add the trace to the chart:
108
chart.addTrace(trace);
109
110     // Make it visible:
111
this.add(new ChartPanel(chart), BorderLayout.CENTER);
112
113   }
114
115 }
116
Popular Tags