KickJava   Java API By Example, From Geeks To Geeks.

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


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  * LineChartDemo3.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: LineChartDemo3.java,v 1.7 2003/11/28 10:57:36 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 27-Jan-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.NumberAxis;
44 import org.jfree.chart.plot.PlotOrientation;
45 import org.jfree.chart.plot.XYPlot;
46 import org.jfree.chart.renderer.StandardXYItemRenderer;
47 import org.jfree.data.XYDataset;
48 import org.jfree.data.XYSeries;
49 import org.jfree.data.XYSeriesCollection;
50 import org.jfree.ui.ApplicationFrame;
51 import org.jfree.ui.RefineryUtilities;
52
53 /**
54  * This line chart demo shows many series, each displaying a different shape.
55  *
56  * @author David Gilbert
57  */

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

65     public LineChartDemo3(String JavaDoc title) {
66
67         super(title);
68
69         // create a dataset...
70
XYSeriesCollection dataset = new XYSeriesCollection();
71         for (int i = 0; i < 10; i++) {
72             XYSeries series = new XYSeries("S" + i);
73             for (int j = 0; j < 10; j++) {
74                 series.add(j, Math.random() * 100);
75             }
76             dataset.addSeries(series);
77         }
78
79         JFreeChart chart = createChart(dataset);
80
81         // add the chart to a panel...
82
ChartPanel chartPanel = new ChartPanel(chart);
83         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
84         setContentPane(chartPanel);
85
86     }
87
88     // ****************************************************************************
89
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
90
// * Please note that commercial support and documentation is available from: *
91
// * *
92
// * http://www.object-refinery.com/jfreechart/support.html *
93
// * *
94
// * This is not only a great service for developers, but is a VERY IMPORTANT *
95
// * source of funding for the JFreeChart project. Please support us so that *
96
// * we can continue developing free software. *
97
// ****************************************************************************
98

99     /**
100      * Creates a chart.
101      *
102      * @param dataset a dataset.
103      *
104      * @return A chart based on the supplied dataset.
105      */

106     private JFreeChart createChart(XYDataset dataset) {
107     
108         JFreeChart chart = ChartFactory.createXYLineChart(
109             "Line Chart Demo 3", // chart title
110
"X", // x axis label
111
"Y", // y axis label
112
dataset, // data
113
PlotOrientation.VERTICAL,
114             true, // include legend
115
true, // tooltips
116
false // urls
117
);
118
119         // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
120

121         // get a reference to the plot for further customisation...
122
XYPlot plot = chart.getXYPlot();
123         StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
124         renderer.setPlotShapes(true);
125
126         // change the auto tick unit selection to integer units only...
127
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
128         rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
129     
130         return chart;
131     }
132     
133     /**
134      * Starting point for the demonstration application.
135      *
136      * @param args ignored.
137      */

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