KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BubblePlotDemo.java
24  * -------------------
25  * (C) Copyright 2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: BubblePlotDemo.java,v 1.6 2003/11/28 10:57:33 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 28-Jan-2003 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.chart.demo;
39
40 import org.jfree.chart.ChartFactory;
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.PlotOrientation;
45 import org.jfree.chart.plot.XYPlot;
46 import org.jfree.data.XYZDataset;
47 import org.jfree.ui.ApplicationFrame;
48 import org.jfree.ui.RefineryUtilities;
49
50 /**
51  * A bubble chart demo.
52  *
53  * @author David Gilbert
54  */

55 public class BubblePlotDemo extends ApplicationFrame {
56
57     /**
58      * A demonstration application showing a bubble chart.
59      *
60      * @param title the frame title.
61      */

62     public BubblePlotDemo(String JavaDoc title) {
63
64         super(title);
65         XYZDataset data = new SampleXYZDataset();
66         JFreeChart chart = createChart(data);
67         
68         ChartPanel chartPanel = new ChartPanel(chart);
69         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
70         chartPanel.setVerticalZoom(true);
71         chartPanel.setHorizontalZoom(true);
72         setContentPane(chartPanel);
73
74     }
75     
76     /**
77      * Creates a chart.
78      *
79      * @param dataset the dataset.
80      *
81      * @return The chart.
82      */

83     private JFreeChart createChart(XYZDataset dataset) {
84         JFreeChart chart = ChartFactory.createBubbleChart(
85             "Bubble Plot Demo",
86             "X",
87             "Y",
88             dataset,
89             PlotOrientation.VERTICAL,
90             true,
91             true,
92             false
93         );
94         XYPlot plot = chart.getXYPlot();
95         plot.setForegroundAlpha(0.65f);
96
97         // increase the margins to account for the fact that the auto-range doesn't take into
98
// account the bubble size...
99
NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
100         domainAxis.setLowerMargin(0.15);
101         domainAxis.setUpperMargin(0.15);
102         NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
103         rangeAxis.setLowerMargin(0.15);
104         rangeAxis.setUpperMargin(0.15);
105         return chart;
106     }
107
108     // ****************************************************************************
109
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
110
// * Please note that commercial support and documentation is available from: *
111
// * *
112
// * http://www.object-refinery.com/jfreechart/support.html *
113
// * *
114
// * This is not only a great service for developers, but is a VERY IMPORTANT *
115
// * source of funding for the JFreeChart project. Please support us so that *
116
// * we can continue developing free software. *
117
// ****************************************************************************
118

119     /**
120      * Starting point for the demonstration application.
121      *
122      * @param args ignored.
123      */

124     public static void main(String JavaDoc[] args) {
125
126         BubblePlotDemo demo = new BubblePlotDemo("Bubble Plot Demo");
127         demo.pack();
128         RefineryUtilities.centerFrameOnScreen(demo);
129         demo.setVisible(true);
130
131     }
132
133 }
134
Popular Tags