KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BarChart3DDemo1.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: BarChart3DDemo1.java,v 1.10 2003/11/28 10:57:35 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 29-May-2002 : Version 1 (DG);
35  * 11-Oct-2002 : Renamed VerticalBar3DDemo --> VerticalBarChart3DDemo (DG);
36  * 13-May-2003 : Renamed VerticalBarChart3DDemo --> BarChart3DDemo1 (DG);
37  * 24-Nov-2003 : Copied dataset creation code into this demo (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.DatasetUtilities;
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 vertical 3D bar chart using data
60  * from a {@link CategoryDataset}.
61  *
62  * @author David Gilbert
63  */

64 public class BarChart3DDemo1 extends ApplicationFrame {
65
66     /**
67      * Creates a new demo.
68      *
69      * @param title the frame title.
70      */

71     public BarChart3DDemo1(String JavaDoc title) {
72
73         super(title);
74         
75         CategoryDataset dataset = createDataset();
76         JFreeChart chart = createChart(dataset);
77
78         // add the chart to a panel...
79
ChartPanel chartPanel = new ChartPanel(chart);
80         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
81         setContentPane(chartPanel);
82
83     }
84
85     /**
86      * Creates a sample dataset.
87      *
88      * @return a sample dataset.
89      */

90    private CategoryDataset createDataset() {
91
92         double[][] data = new double[][]
93             {{10.0, 4.0, 15.0, 14.0},
94              {-5.0, -7.0, 14.0, -3.0},
95              {6.0, 17.0, -12.0, 7.0},
96              {7.0, 15.0, 11.0, 0.0},
97              {-8.0, -6.0, 10.0, -9.0},
98              {9.0, 8.0, 0.0, 6.0},
99              {-10.0, 9.0, 7.0, 7.0},
100              {11.0, 13.0, 9.0, 9.0},
101              {-3.0, 7.0, 11.0, -10.0}};
102              
103         return DatasetUtilities.createCategoryDataset("Series ", "Category ", data);
104
105     }
106     
107     /**
108      * Creates a chart.
109      *
110      * @param dataset the dataset.
111      *
112      * @return The chart.
113      */

114     private JFreeChart createChart(CategoryDataset dataset) {
115         
116         JFreeChart chart = ChartFactory.createBarChart3D(
117             "3D Bar Chart Demo", // chart title
118
"Category", // domain axis label
119
"Value", // range axis label
120
dataset, // data
121
PlotOrientation.VERTICAL, // orientation
122
true, // include legend
123
true, // tooltips
124
false // urls
125
);
126
127         CategoryPlot plot = chart.getCategoryPlot();
128         CategoryAxis axis = plot.getDomainAxis();
129         CategoryLabelPosition position = new CategoryLabelPosition(
130             RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 8.0
131         );
132         axis.setBottomCategoryLabelPosition(position);
133         
134         return chart;
135
136     }
137     
138     // ****************************************************************************
139
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
140
// * Please note that commercial support and documentation is available from: *
141
// * *
142
// * http://www.object-refinery.com/jfreechart/support.html *
143
// * *
144
// * This is not only a great service for developers, but is a VERY IMPORTANT *
145
// * source of funding for the JFreeChart project. Please support us so that *
146
// * we can continue developing free software. *
147
// ****************************************************************************
148

149     /**
150      * Starting point for the demonstration application.
151      *
152      * @param args ignored.
153      */

154     public static void main(String JavaDoc[] args) {
155
156         BarChart3DDemo1 demo = new BarChart3DDemo1("3D Bar Chart Demo 1");
157         demo.pack();
158         RefineryUtilities.centerFrameOnScreen(demo);
159         demo.setVisible(true);
160
161     }
162
163 }
164
Popular Tags