KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > demo > XYLogAxesDemo


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
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  * ------------------
23  * XYLogAxesDemo.java
24  * ------------------
25  * (C) Copyright 2002, 2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): Clemens;
29  *
30  * $Id: XYLogAxesDemo.java,v 1.9 2003/11/28 10:57:34 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 31-Jul-2002 : Version 1 (DG);
35  * 11-Oct-2002 : Fixed issues reported by Checkstyle (DG);
36  * 31-Jan-2003 : Replaced DefaultXYDataset with XYSeriesCollection (DG);
37  *
38  */

39 package org.jfree.chart.demo;
40
41 import java.awt.Color JavaDoc;
42
43 import org.jfree.chart.ChartFactory;
44 import org.jfree.chart.ChartPanel;
45 import org.jfree.chart.JFreeChart;
46 import org.jfree.chart.axis.LogarithmicAxis;
47 import org.jfree.chart.axis.NumberAxis;
48 import org.jfree.chart.plot.PlotOrientation;
49 import org.jfree.chart.plot.XYPlot;
50 import org.jfree.data.XYSeries;
51 import org.jfree.data.XYSeriesCollection;
52 import org.jfree.ui.ApplicationFrame;
53 import org.jfree.ui.RefineryUtilities;
54
55 /**
56  * A demo showing the use of log axes.
57  *
58  * @author David Gilbert
59  */

60 public class XYLogAxesDemo extends ApplicationFrame {
61
62     /**
63      * Creates a new demo.
64      *
65      * @param title the frame title.
66      */

67     public XYLogAxesDemo(String JavaDoc title) {
68
69         super(title);
70
71         //Object[][][] data = new Object[3][50][2];
72
XYSeries s1 = new XYSeries("Series 1");
73         XYSeries s2 = new XYSeries("Series 2");
74         XYSeries s3 = new XYSeries("Series 3");
75
76 // for (int i = 1; i <= 50; i++) {
77
// s1.add(i, 1000 * Math.pow(i, -2));
78
// s2.add(i, 1000 * Math.pow(i, -3));
79
// s3.add(i, 1000 * Math.pow(i, -4));
80
// }
81

82         for (int i = 1; i <= 50; i++) {
83             s1.add(i, 10 * Math.exp(i / 5.0));
84             s2.add(i, 20 * Math.exp(i / 5.0));
85             s3.add(i, 30 * Math.exp(i / 5.0));
86         }
87
88         XYSeriesCollection dataset = new XYSeriesCollection();
89         dataset.addSeries(s1);
90         dataset.addSeries(s2);
91         dataset.addSeries(s3);
92
93         JFreeChart chart = ChartFactory.createXYLineChart(
94             "Log Axis Demo", // chart title
95
"Category", // domain axis label
96
"Value", // range axis label
97
dataset, // data
98
PlotOrientation.VERTICAL,
99             true, // include legend
100
true,
101             false
102         );
103
104         XYPlot plot = chart.getXYPlot();
105         NumberAxis domainAxis = new NumberAxis("x");
106         NumberAxis rangeAxis = new LogarithmicAxis("Log(y)");
107         plot.setDomainAxis(domainAxis);
108         plot.setRangeAxis(rangeAxis);
109         chart.setBackgroundPaint(Color.white);
110         plot.setOutlinePaint(Color.black);
111         ChartPanel chartPanel = new ChartPanel(chart);
112         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
113         setContentPane(chartPanel);
114
115     }
116
117     // ****************************************************************************
118
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
119
// * Please note that commercial support and documentation is available from: *
120
// * *
121
// * http://www.object-refinery.com/jfreechart/support.html *
122
// * *
123
// * This is not only a great service for developers, but is a VERY IMPORTANT *
124
// * source of funding for the JFreeChart project. Please support us so that *
125
// * we can continue developing free software. *
126
// ****************************************************************************
127

128     /**
129      * Starting point for the demonstration application.
130      *
131      * @param args ignored.
132      */

133     public static void main(String JavaDoc[] args) {
134
135         XYLogAxesDemo demo = new XYLogAxesDemo("XY Log Axes Demo");
136         demo.pack();
137         RefineryUtilities.centerFrameOnScreen(demo);
138         demo.setVisible(true);
139
140     }
141
142 }
143
Popular Tags