KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 package info.monitorenter.gui.chart.demos;
24
25 import info.monitorenter.gui.chart.Chart2D;
26 import info.monitorenter.gui.chart.IAxis;
27 import info.monitorenter.gui.chart.ITrace2D;
28 import info.monitorenter.gui.chart.axis.AxisLog10;
29 import info.monitorenter.gui.chart.labelformatters.LabelFormatterAutoUnits;
30 import info.monitorenter.gui.chart.labelformatters.LabelFormatterNumber;
31 import info.monitorenter.gui.chart.layout.ChartPanel;
32 import info.monitorenter.gui.chart.traces.Trace2DSimple;
33 import info.monitorenter.gui.chart.traces.painters.TracePainterDisc;
34
35 import java.awt.Color JavaDoc;
36 import java.awt.event.WindowAdapter JavaDoc;
37 import java.awt.event.WindowEvent JavaDoc;
38 import java.text.DecimalFormat JavaDoc;
39
40 import javax.swing.JFrame JavaDoc;
41
42 /**
43  * A demo chart that uses a logarithmic axis for Y ({@link info.monitorenter.gui.chart.axis.AxisLog10})
44  * and a trace painter for discs ({@link info.monitorenter.gui.chart.traces.painters.TracePainterDisc}).
45  * <p>
46  *
47  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
48  *
49  * @version $Revision: 1.1 $
50  *
51  */

52 public final class Log10AxisChart {
53
54   /**
55    * Main entry.
56    * <p>
57    *
58    * @param args
59    * ignored.
60    */

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

101   private Log10AxisChart() {
102     // nop
103
}
104 }
105
Popular Tags