KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SymbolicChartDemo.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: SymbolicChartDemo1.java,v 1.9 2003/11/28 10:57:33 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 14-Feb-2003 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.chart.demo;
39
40 import org.jfree.chart.ChartPanel;
41 import org.jfree.chart.JFreeChart;
42 import org.jfree.chart.axis.NumberAxis;
43 import org.jfree.chart.axis.SymbolicAxis;
44 import org.jfree.chart.axis.ValueAxis;
45 import org.jfree.chart.labels.SymbolicXYToolTipGenerator;
46 import org.jfree.chart.plot.XYPlot;
47 import org.jfree.chart.renderer.StandardXYItemRenderer;
48 import org.jfree.chart.renderer.XYItemRenderer;
49 import org.jfree.data.XYDataset;
50 import org.jfree.data.YisSymbolic;
51 import org.jfree.ui.ApplicationFrame;
52 import org.jfree.ui.RefineryUtilities;
53
54 /**
55  * An example of...
56  *
57  * @author David Gilbert
58  */

59 public class SymbolicChartDemo1 extends ApplicationFrame {
60
61     /**
62      * A demonstration application.
63      *
64      * @param title the frame title.
65      */

66     public SymbolicChartDemo1(String JavaDoc title) {
67
68         super(title);
69
70         // create a title...
71
XYDataset dataset = createDataset();
72
73         ValueAxis domainAxis = new NumberAxis("X");
74         SymbolicAxis symbolicAxis
75             = new SymbolicAxis("Y", ((YisSymbolic) dataset).getYSymbolicValues());
76
77         XYPlot plot = new XYPlot(dataset, domainAxis, symbolicAxis, null);
78         XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES,
79                                                              new SymbolicXYToolTipGenerator());
80         plot.setRenderer(renderer);
81         JFreeChart chart = new JFreeChart(title, plot);
82
83         ChartPanel chartPanel = new ChartPanel(chart);
84         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
85         setContentPane(chartPanel);
86
87     }
88
89     // ****************************************************************************
90
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
91
// * Please note that commercial support and documentation is available from: *
92
// * *
93
// * http://www.object-refinery.com/jfreechart/support.html *
94
// * *
95
// * This is not only a great service for developers, but is a VERY IMPORTANT *
96
// * source of funding for the JFreeChart project. Please support us so that *
97
// * we can continue developing free software. *
98
// ****************************************************************************
99

100     /**
101      * Creates a dataset, consisting of two series of monthly data.
102      *
103      * @return the dataset.
104      */

105     public XYDataset createDataset() {
106
107         String JavaDoc[] sData = {"Giraffe", "Gazelle", "Zebra", "Gnu"};
108         SampleYSymbolicDataset data
109             = new SampleYSymbolicDataset("BY Sample", 40, sData, 4, 20,
110                 new String JavaDoc[] {"B Fall", "B Spring", "B Summer", "B Winter"});
111         return data;
112
113     }
114
115     /**
116      * Starting point for the demonstration application.
117      *
118      * @param args ignored.
119      */

120     public static void main(String JavaDoc[] args) {
121
122         SymbolicChartDemo1 demo = new SymbolicChartDemo1("Symbolic Chart Demo 1");
123         demo.pack();
124         RefineryUtilities.centerFrameOnScreen(demo);
125         demo.setVisible(true);
126
127     }
128
129 }
130
131
Popular Tags