KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BarChart3DDemo2.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: BarChart3DDemo2.java,v 1.11 2003/11/28 10:57:36 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 29-May-2002 : Version 1 (DG);
35  * 10-Oct-2002 : Fixed errors reported by Checkstyle (DG);
36  * 05-Nov-2002 : Renamed HorizontalBarChart3DDemo.java (DG);
37  * 13-May-2003 : Renamed BarChart3DDemo2.java (DG);
38  *
39  */

40
41 package org.jfree.chart.demo;
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.CategoryAxis;
47 import org.jfree.chart.axis.CategoryLabelPosition;
48 import org.jfree.chart.plot.CategoryPlot;
49 import org.jfree.chart.plot.PlotOrientation;
50 import org.jfree.data.CategoryDataset;
51 import org.jfree.data.DefaultCategoryDataset;
52 import org.jfree.text.TextBlockAnchor;
53 import org.jfree.ui.ApplicationFrame;
54 import org.jfree.ui.RectangleAnchor;
55 import org.jfree.ui.RefineryUtilities;
56 import org.jfree.ui.TextAnchor;
57
58 /**
59  * A simple demonstration application showing how to create a horizontal 3D bar chart using data
60  * from a {@link CategoryDataset}.
61  *
62  * @author David Gilbert
63  */

64 public class BarChart3DDemo2 extends ApplicationFrame {
65
66     // ****************************************************************************
67
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
68
// * Please note that commercial support and documentation is available from: *
69
// * *
70
// * http://www.object-refinery.com/jfreechart/support.html *
71
// * *
72
// * This is not only a great service for developers, but is a VERY IMPORTANT *
73
// * source of funding for the JFreeChart project. Please support us so that *
74
// * we can continue developing free software. *
75
// ****************************************************************************
76

77     /**
78      * Creates a new demo.
79      *
80      * @param title the frame title.
81      */

82     public BarChart3DDemo2(String JavaDoc title) {
83
84         super(title);
85         
86         // create the chart...
87
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
88         dataset.addValue(23.0, "Series 1", "London");
89         dataset.addValue(14.0, "Series 1", "New York");
90         dataset.addValue(14.0, "Series 1", "Istanbul");
91         dataset.addValue(14.0, "Series 1", "Cairo");
92         dataset.addValue(13.0, "Series 2", "London");
93         dataset.addValue(19.0, "Series 2", "New York");
94         dataset.addValue(19.0, "Series 2", "Istanbul");
95         dataset.addValue(19.0, "Series 2", "Cairo");
96         dataset.addValue(7.0, "Series 3", "London");
97         dataset.addValue(9.0, "Series 3", "New York");
98         dataset.addValue(9.0, "Series 3", "Istanbul");
99         dataset.addValue(9.0, "Series 3", "Cairo");
100         
101         JFreeChart chart = createChart(dataset);
102         
103         // add the chart to a panel...
104
ChartPanel chartPanel = new ChartPanel(chart);
105         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
106         setContentPane(chartPanel);
107
108     }
109
110     /**
111      * Creates a chart.
112      *
113      * @param dataset the dataset.
114      *
115      * @return The chart.
116      */

117     private JFreeChart createChart(CategoryDataset dataset) {
118         
119         JFreeChart chart = ChartFactory.createBarChart3D(
120             "3D Bar Chart Demo 2", // chart title
121
"Category", // domain axis label
122
"Value", // range axis label
123
dataset, // data
124
PlotOrientation.HORIZONTAL, // orientation
125
true, // include legend
126
true, // tooltips
127
false // urls
128
);
129
130         CategoryPlot plot = chart.getCategoryPlot();
131         plot.setForegroundAlpha(1.0f);
132         
133         CategoryAxis axis = plot.getDomainAxis();
134         CategoryLabelPosition position = new CategoryLabelPosition(
135             RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0
136         );
137         axis.setLeftCategoryLabelPosition(position);
138                 
139         return chart;
140     
141     }
142     
143     /**
144      * Starting point for the demonstration application.
145      *
146      * @param args ignored.
147      */

148     public static void main(String JavaDoc[] args) {
149
150         BarChart3DDemo2 demo = new BarChart3DDemo2("3D Bar Chart Demo 2");
151         demo.pack();
152         RefineryUtilities.centerFrameOnScreen(demo);
153         demo.setVisible(true);
154
155     }
156
157 }
158
Popular Tags