KickJava   Java API By Example, From Geeks To Geeks.

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


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  * LayeredBarChartDemo2.java
24  * -------------------------
25  * (C) Copyright 2003, by Arnaud Lelievre and Contributors.
26  *
27  * Original Author: Arnaud Lelievre (for Garden);
28  * Contributor(s): -;
29  *
30  *
31  * Changes
32  * -------
33  * 28-Aug-2003 : Version 1 (AL);
34  *
35  */

36
37 package org.jfree.chart.demo;
38
39 import java.awt.Color JavaDoc;
40
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.NumberAxis;
45 import org.jfree.chart.axis.ValueAxis;
46 import org.jfree.chart.plot.CategoryPlot;
47 import org.jfree.chart.renderer.LayeredBarRenderer;
48 import org.jfree.data.CategoryDataset;
49 import org.jfree.data.DatasetUtilities;
50 import org.jfree.ui.ApplicationFrame;
51 import org.jfree.ui.RefineryUtilities;
52
53 /**
54  * A simple demonstration application showing how to create a superimposed vertical bar chart.
55  *
56  * @author Arnaud Lelievre
57  */

58 public class LayeredBarChartDemo2 extends ApplicationFrame {
59
60     /**
61      * Creates a new demo instance.
62      *
63      * @param title the frame title.
64      */

65     public LayeredBarChartDemo2(String JavaDoc title) {
66
67         super(title);
68
69         // create a dataset...
70
double[][] data = new double[][] {
71             {41.0, 33.0, 22.0, 64.0, 42.0, 62.0, 22.0, 14.0},
72             {55.0, 63.0, 55.0, 48.0, 54.0, 37.0, 41.0, 39.0},
73             {57.0, 75.0, 43.0, 33.0, 63.0, 46.0, 57.0, 33.0}
74         };
75
76         CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ",
77                                                                          "Factor ",
78                                                                          data);
79
80         // create the chart...
81
CategoryAxis categoryAxis = new CategoryAxis("Category");
82         ValueAxis valueAxis = new NumberAxis("Score (%)");
83
84
85         CategoryPlot plot = new CategoryPlot(dataset,
86                                              categoryAxis,
87                                              valueAxis,
88                                              new LayeredBarRenderer());
89         
90         plot.setOrientation(org.jfree.chart.plot.PlotOrientation.VERTICAL);
91         JFreeChart chart = new JFreeChart(
92             "Layered Bar Chart Demo 2",
93             JFreeChart.DEFAULT_TITLE_FONT,
94             plot,
95             true
96         );
97         
98         // set the background color for the chart...
99
chart.setBackgroundPaint(Color.lightGray);
100
101         LayeredBarRenderer renderer = (LayeredBarRenderer) plot.getRenderer();
102
103         // we can set each series bar width individually or let the renderer manage a standard view.
104
// the width is set in percentage, where 1.0 is the maximum (100%).
105
renderer.setSeriesBarWidth(0, 1.0);
106         renderer.setSeriesBarWidth(1, 0.7);
107         renderer.setSeriesBarWidth(2, 0.5);
108
109         renderer.setItemMargin(0.01);
110
111         CategoryAxis domainAxis = plot.getDomainAxis();
112         domainAxis.setCategoryMargin(0.25);
113         domainAxis.setUpperMargin(0.05);
114         domainAxis.setLowerMargin(0.05);
115
116         // add the chart to a panel...
117
ChartPanel chartPanel = new ChartPanel(chart);
118         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
119         setContentPane(chartPanel);
120
121     }
122
123     // ****************************************************************************
124
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
125
// * Please note that commercial support and documentation is available from: *
126
// * *
127
// * http://www.object-refinery.com/jfreechart/support.html *
128
// * *
129
// * This is not only a great service for developers, but is a VERY IMPORTANT *
130
// * source of funding for the JFreeChart project. Please support us so that *
131
// * we can continue developing free software. *
132
// ****************************************************************************
133

134     /**
135      * Starting point for the demonstration application.
136      *
137      * @param args ignored.
138      */

139     public static void main(String JavaDoc[] args) {
140
141         LayeredBarChartDemo2 demo = new LayeredBarChartDemo2("Layered Bar Chart Demo 2");
142         demo.pack();
143         RefineryUtilities.centerFrameOnScreen(demo);
144         demo.setVisible(true);
145
146     }
147
148 }
149
Popular Tags