KickJava   Java API By Example, From Geeks To Geeks.

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


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  * FastScatterPlotDemo.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): -;
29  *
30  * $Id: FastScatterPlotDemo.java,v 1.6 2003/11/28 10:57:35 mungady Exp $
31  *
32  * Changes (from 29-Oct-2002)
33  * --------------------------
34  * 29-Oct-2002 : Added standard header and Javadocs (DG);
35  * 12-Nov-2003 : Enabled zooming (DG);
36  *
37  */

38
39 package org.jfree.chart.demo;
40
41 import org.jfree.chart.ChartPanel;
42 import org.jfree.chart.JFreeChart;
43 import org.jfree.chart.axis.NumberAxis;
44 import org.jfree.chart.plot.FastScatterPlot;
45 import org.jfree.ui.ApplicationFrame;
46 import org.jfree.ui.RefineryUtilities;
47
48 /**
49  * A demo of the fast scatter plot.
50  *
51  * @author David Gilbert
52  */

53 public class FastScatterPlotDemo extends ApplicationFrame {
54
55     /** A constant for the number of items in the sample dataset. */
56     private static final int COUNT = 500000;
57
58     /** The data. */
59     private float[][] data = new float[2][COUNT];
60
61     /**
62      * Creates a new fast scatter plot demo.
63      *
64      * @param title the frame title.
65      */

66     public FastScatterPlotDemo(String JavaDoc title) {
67
68         super(title);
69         populateData();
70         NumberAxis domainAxis = new NumberAxis("X");
71         domainAxis.setAutoRangeIncludesZero(false);
72         NumberAxis rangeAxis = new NumberAxis("Y");
73         rangeAxis.setAutoRangeIncludesZero(false);
74         FastScatterPlot plot = new FastScatterPlot(data, domainAxis, rangeAxis);
75         JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
76         chart.setLegend(null);
77         chart.setAntiAlias(false);
78         ChartPanel panel = new ChartPanel(chart, true);
79         panel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
80         panel.setHorizontalZoom(true);
81         panel.setVerticalZoom(true);
82         panel.setMinimumDrawHeight(10);
83         panel.setMaximumDrawHeight(2000);
84         panel.setMinimumDrawWidth(20);
85         panel.setMaximumDrawWidth(2000);
86         
87         setContentPane(panel);
88
89     }
90
91     // ****************************************************************************
92
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
93
// * Please note that commercial support and documentation is available from: *
94
// * *
95
// * http://www.object-refinery.com/jfreechart/support.html *
96
// * *
97
// * This is not only a great service for developers, but is a VERY IMPORTANT *
98
// * source of funding for the JFreeChart project. Please support us so that *
99
// * we can continue developing free software. *
100
// ****************************************************************************
101

102     /**
103      * Populates the data array with random values.
104      */

105     private void populateData() {
106
107         for (int i = 0; i < data[0].length; i++) {
108             float x = (float) i + 100000;
109             data[0][i] = x;
110             data[1][i] = 100000 + (float) Math.random() * COUNT;
111         }
112
113     }
114
115     /**
116      * Starting point for the demonstration application.
117      *
118      * @param args ignored.
119      */

120     public static void main(String JavaDoc[] args) {
121
122         FastScatterPlotDemo demo = new FastScatterPlotDemo("Fast Scatter Plot Demo");
123         demo.pack();
124         RefineryUtilities.centerFrameOnScreen(demo);
125         demo.setVisible(true);
126
127     }
128
129 }
130
Popular Tags