KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  *
3  * LogAxisChart.java, rendering demo of 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.Chart2D;
27 import info.monitorenter.gui.chart.ITrace2D;
28 import info.monitorenter.gui.chart.axis.AxisLogE;
29 import info.monitorenter.gui.chart.layout.ChartPanel;
30 import info.monitorenter.gui.chart.traces.Trace2DSimple;
31 import info.monitorenter.gui.chart.traces.painters.TracePainterDisc;
32
33 import java.awt.Color JavaDoc;
34 import java.awt.event.WindowAdapter JavaDoc;
35 import java.awt.event.WindowEvent JavaDoc;
36
37 import javax.swing.JFrame JavaDoc;
38
39 /**
40  * A demo chart that uses a logarithmic axis for Y ({@link info.monitorenter.gui.chart.axis.AxisLog10})
41  * and a trace painter for discs ({@link info.monitorenter.gui.chart.traces.painters.TracePainterDisc}).
42  * <p>
43  *
44  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
45  *
46  * @version $Revision: 1.1 $
47  *
48  */

49 public final class LogAxisChart {
50
51   /**
52    * Main entry.
53    * <p>
54    *
55    * @param args
56    * ignored.
57    */

58   public static void main(final String JavaDoc[] args) {
59
60     // Create a chart:
61
Chart2D chart = new Chart2D();
62     // set a special axis:
63
chart.setAxisY(new AxisLogE());
64
65     // Create an ITrace:
66
ITrace2D trace = new Trace2DSimple();
67     trace.setTracePainter(new TracePainterDisc());
68     trace.setColor(Color.DARK_GRAY);
69     // Add the function 1/x + random
70
for (int i = 1; i < 50; i++) {
71       trace.addPoint(i, Math.exp(i));
72     }
73     // Add the trace to the chart:
74
chart.addTrace(trace);
75
76     // Make it visible:
77
// Create a frame.
78
JFrame JavaDoc frame = new JFrame JavaDoc(LogAxisChart.class.getName());
79     // add the chart to the frame:
80
frame.getContentPane().add(new ChartPanel(chart));
81     frame.setSize(400, 300);
82     // Enable the termination button [cross on the upper right edge]:
83
frame.addWindowListener(new WindowAdapter JavaDoc() {
84       public void windowClosing(final WindowEvent JavaDoc e) {
85         System.exit(0);
86       }
87     });
88     frame.setVisible(true);
89   }
90
91   /**
92    * Defcon.
93    * <p>
94    */

95   private LogAxisChart() {
96     // nop
97
}
98 }
99
Popular Tags