KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BarChart3DDemo3.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: BarChart3DDemo3.java,v 1.3 2003/11/28 10:57:33 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 24-Nov-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.CategoryAxis;
44 import org.jfree.chart.axis.CategoryLabelPosition;
45 import org.jfree.chart.plot.CategoryPlot;
46 import org.jfree.chart.plot.PlotOrientation;
47 import org.jfree.chart.renderer.BarRenderer;
48 import org.jfree.chart.renderer.CategoryItemRenderer;
49 import org.jfree.data.CategoryDataset;
50 import org.jfree.data.DefaultCategoryDataset;
51 import org.jfree.text.TextBlockAnchor;
52 import org.jfree.ui.ApplicationFrame;
53 import org.jfree.ui.RectangleAnchor;
54 import org.jfree.ui.RefineryUtilities;
55 import org.jfree.ui.TextAnchor;
56
57 /**
58  * This demonstration shows a 3D bar chart with item labels displayed.
59  *
60  * @author David Gilbert
61  */

62 public class BarChart3DDemo3 extends ApplicationFrame {
63
64     /**
65      * Creates a new demo.
66      *
67      * @param title the frame title.
68      */

69     public BarChart3DDemo3(String JavaDoc title) {
70
71         super(title);
72         
73         CategoryDataset dataset = createDataset();
74         JFreeChart chart = createChart(dataset);
75         ChartPanel chartPanel = new ChartPanel(chart);
76         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
77         setContentPane(chartPanel);
78
79     }
80
81     // ****************************************************************************
82
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
83
// * Please note that commercial support and documentation is available from: *
84
// * *
85
// * http://www.object-refinery.com/jfreechart/support.html *
86
// * *
87
// * This is not only a great service for developers, but is a VERY IMPORTANT *
88
// * source of funding for the JFreeChart project. Please support us so that *
89
// * we can continue developing free software. *
90
// ****************************************************************************
91

92     /**
93      * Creates a sample dataset.
94      *
95      * @return a sample dataset.
96      */

97    private CategoryDataset createDataset() {
98
99         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
100         dataset.addValue(25.0, "Series 1", "Category 1");
101         dataset.addValue(34.0, "Series 1", "Category 2");
102         dataset.addValue(19.0, "Series 2", "Category 1");
103         dataset.addValue(29.0, "Series 2", "Category 2");
104         dataset.addValue(41.0, "Series 3", "Category 1");
105         dataset.addValue(33.0, "Series 3", "Category 2");
106         return dataset;
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", // chart title
121
"Category", // domain axis label
122
"Value", // range axis label
123
dataset, // data
124
PlotOrientation.VERTICAL, // orientation
125
true, // include legend
126
true, // tooltips
127
false // urls
128
);
129
130         CategoryPlot plot = chart.getCategoryPlot();
131         CategoryAxis axis = plot.getDomainAxis();
132         CategoryLabelPosition position = new CategoryLabelPosition(
133             RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 8.0
134         );
135         axis.setBottomCategoryLabelPosition(position);
136         
137         CategoryItemRenderer renderer = plot.getRenderer();
138         renderer.setItemLabelsVisible(true);
139         BarRenderer r = (BarRenderer) renderer;
140         r.setMaxBarWidth(0.05);
141         
142         return chart;
143
144     }
145     
146     
147     /**
148      * Starting point for the demonstration application.
149      *
150      * @param args ignored.
151      */

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