KickJava   Java API By Example, From Geeks To Geeks.

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


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  * JFreeChartDemoBase.java
24  * -----------------------
25  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): Andrzej Porebski;
29  * Matthew Wright;
30  * Serge V. Grachov;
31  * Bill Kelemen;
32  * Achilleus Mantzios;
33  * Bryan Scott;
34  *
35  * $Id: JFreeChartDemoBase.java,v 1.24 2003/11/25 09:34:06 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 27-Jul-2002 : Created (BRS);
40  * 10-Oct-2002 : Fixed errors reported by Checkstyle (DG);
41  *
42  */

43
44 package org.jfree.chart.demo;
45
46 import java.awt.Color JavaDoc;
47 import java.awt.Font JavaDoc;
48 import java.awt.GradientPaint JavaDoc;
49 import java.lang.reflect.Method JavaDoc;
50 import java.util.Calendar JavaDoc;
51 import java.util.Date JavaDoc;
52 import java.util.ResourceBundle JavaDoc;
53
54 import org.jfree.chart.ChartFactory;
55 import org.jfree.chart.JFreeChart;
56 import org.jfree.chart.Legend;
57 import org.jfree.chart.Spacer;
58 import org.jfree.chart.TextTitle;
59 import org.jfree.chart.axis.DateAxis;
60 import org.jfree.chart.axis.LogarithmicAxis;
61 import org.jfree.chart.axis.NumberAxis;
62 import org.jfree.chart.axis.ValueAxis;
63 import org.jfree.chart.labels.HighLowToolTipGenerator;
64 import org.jfree.chart.labels.TimeSeriesToolTipGenerator;
65 import org.jfree.chart.plot.CategoryPlot;
66 import org.jfree.chart.plot.CombinedDomainXYPlot;
67 import org.jfree.chart.plot.CombinedRangeXYPlot;
68 import org.jfree.chart.plot.CompassPlot;
69 import org.jfree.chart.plot.DialShape;
70 import org.jfree.chart.plot.MeterPlot;
71 import org.jfree.chart.plot.PiePlot;
72 import org.jfree.chart.plot.Plot;
73 import org.jfree.chart.plot.PlotOrientation;
74 import org.jfree.chart.plot.ThermometerPlot;
75 import org.jfree.chart.plot.XYPlot;
76 import org.jfree.chart.renderer.HighLowRenderer;
77 import org.jfree.chart.renderer.StandardXYItemRenderer;
78 import org.jfree.chart.renderer.XYBarRenderer;
79 import org.jfree.chart.renderer.XYItemRenderer;
80 import org.jfree.data.CategoryDataset;
81 import org.jfree.data.CombinedDataset;
82 import org.jfree.data.DatasetUtilities;
83 import org.jfree.data.DefaultValueDataset;
84 import org.jfree.data.HighLowDataset;
85 import org.jfree.data.IntervalCategoryDataset;
86 import org.jfree.data.MovingAverage;
87 import org.jfree.data.PieDataset;
88 import org.jfree.data.SignalsDataset;
89 import org.jfree.data.SubSeriesDataset;
90 import org.jfree.data.WindDataset;
91 import org.jfree.data.XYDataset;
92 import org.jfree.data.gantt.Task;
93 import org.jfree.data.gantt.TaskSeries;
94 import org.jfree.data.gantt.TaskSeriesCollection;
95 import org.jfree.data.time.SimpleTimePeriod;
96 import org.jfree.data.time.TimeSeries;
97 import org.jfree.data.time.TimeSeriesCollection;
98
99 /**
100  * A simple class that allows the swing and servlet chart demonstrations
101  * to share chart generating code.
102  *
103  * If you would like to add a chart to the swing and/or servlet demo do so here.
104  *
105  * @author Bryan Scott
106  * @author David Gilbert
107  */

108 public class JFreeChartDemoBase {
109
110     /**
111      * CHART_COMMANDS holds information on charts that can be created
112      * Format is
113      * Name, Creation Method, Resource file prefix
114      *
115      * Steps To add a chart
116      * 1) Create a createChart method which returns a JFreeChart
117      * 2) Append details to CHART_COMMANDS
118      * 3) Append details to DemoResources
119      */

120     public static final String JavaDoc[][] CHART_COMMANDS = {
121         {"HORIZONTAL_BAR_CHART", "createHorizontalBarChart", "chart1"},
122         {"HORIZONTAL_STACKED_BAR_CHART", "createStackedHorizontalBarChart", "chart2"},
123         {"VERTICAL_BAR_CHART", "createVerticalBarChart", "chart3"},
124         {"VERTICAL_3D_BAR_CHART", "createVertical3DBarChart", "chart4"},
125         {"VERTICAL_STACKED_BAR_CHART", "createVerticalStackedBarChart", "chart5"},
126         {"VERTICAL_STACKED_3D_BAR_CHART", "createVerticalStacked3DBarChart", "chart6"},
127         {"PIE_CHART_1", "createPieChartOne", "chart7"},
128         {"PIE_CHART_2", "createPieChartTwo", "chart8"},
129         {"XY_PLOT", "createXYPlot", "chart9"},
130         {"TIME_SERIES_1_CHART", "createTimeSeries1Chart", "chart10"},
131         {"TIME_SERIES_2_CHART", "createTimeSeries2Chart", "chart11"},
132         {"TIME_SERIES_WITH_MA_CHART", "createTimeSeriesWithMAChart", "chart12"},
133         {"HIGH_LOW_CHART", "createHighLowChart", "chart13"},
134         {"CANDLESTICK_CHART", "createCandlestickChart", "chart14"},
135         {"SIGNAL_CHART", "createSignalChart", "chart15"},
136         {"WIND_PLOT", "createWindPlot", "chart16"},
137         {"SCATTER_PLOT", "createScatterPlot", "chart17"},
138         {"LINE_CHART", "createLineChart", "chart18"},
139         {"VERTICAL_XY_BAR_CHART", "createVerticalXYBarChart", "chart19"},
140         {"XY_PLOT_NULL", "createNullXYPlot", "chart20"},
141         {"XY_PLOT_ZERO", "createXYPlotZeroData", "chart21"},
142         {"TIME_SERIES_CHART_SCROLL", "createTimeSeriesChartInScrollPane", "chart22"},
143         {"SINGLE_SERIES_BAR_CHART", "createSingleSeriesBarChart", "chart23"},
144         {"DYNAMIC_CHART", "createDynamicXYChart", "chart24"},
145         {"OVERLAID_CHART", "createOverlaidChart", "chart25"},
146         {"HORIZONTALLY_COMBINED_CHART", "createHorizontallyCombinedChart", "chart26"},
147         {"VERTICALLY_COMBINED_CHART", "createVerticallyCombinedChart", "chart27"},
148         {"COMBINED_OVERLAID_CHART", "createCombinedAndOverlaidChart1", "chart28"},
149         {"COMBINED_OVERLAID_DYNAMIC_CHART", "createCombinedAndOverlaidDynamicXYChart", "chart29"},
150         {"THERMOMETER_CHART", "createThermometerChart", "chart30"},
151         {"METER_CHART", "createMeterChartCircle", "chart31"},
152         {"GANTT_CHART", "createGanttChart", "chart32"},
153         {"METER_CHART2", "createMeterChartPie", "chart33"},
154         {"METER_CHART3", "createMeterChartChord", "chart34"},
155         {"COMPASS_CHART", "createCompassChart", "chart35"},
156     };
157
158     /** Base class name for localised resources. */
159     public static final String JavaDoc BASE_RESOURCE_CLASS
160         = "org.jfree.chart.demo.resources.DemoResources";
161
162     /** Localised resources. */
163     private ResourceBundle JavaDoc resources;
164
165     /** An array of charts. */
166     private JFreeChart[] charts = new JFreeChart[CHART_COMMANDS.length];
167
168     /**
169      * Default constructor.
170      */

171     public JFreeChartDemoBase() {
172         this.resources = ResourceBundle.getBundle(BASE_RESOURCE_CLASS);
173     }
174
175     /**
176      * Returns a chart.
177      *
178      * @param i the chart index.
179      *
180      * @return a chart.
181      */

182     public JFreeChart getChart(int i) {
183
184         if ((i < 0) && (i >= charts.length)) {
185             i = 0;
186         }
187
188         if (charts[i] == null) {
189             /// Utilise reflection to invoke method to create new chart if required.
190
try {
191                 Method JavaDoc method = getClass().getDeclaredMethod(CHART_COMMANDS[i][1], null);
192                 charts[i] = (JFreeChart) method.invoke(this, null);
193             }
194             catch (Exception JavaDoc ex) {
195                 ex.printStackTrace();
196             }
197         }
198         return charts[i];
199     }
200
201     /**
202      * This makes the resources bundle available. Basically an optimisation so
203      * the demo servlet can access the same resource file.
204      * @return the resources bundle.
205      */

206     public ResourceBundle JavaDoc getResources() {
207       return this.resources;
208     }
209
210     /**
211      * Create a horizontal bar chart.
212      *
213      * @return a horizontal bar chart.
214      */

215     public JFreeChart createHorizontalBarChart() {
216
217         // create a default chart based on some sample data...
218
String JavaDoc title = resources.getString("bar.horizontal.title");
219         String JavaDoc domain = resources.getString("bar.horizontal.domain");
220         String JavaDoc range = resources.getString("bar.horizontal.range");
221
222         CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
223         JFreeChart chart = ChartFactory.createBarChart(title, domain, range, data,
224                                                        PlotOrientation.HORIZONTAL,
225                                                        true,
226                                                        true,
227                                                        false);
228
229         // then customise it a little...
230
chart.getLegend().setAnchor(Legend.EAST);
231         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.orange));
232         CategoryPlot plot = chart.getCategoryPlot();
233         plot.setRangeCrosshairVisible(false);
234         NumberAxis axis = (NumberAxis) plot.getRangeAxis();
235         axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
236         axis.setInverted(true);
237
238         return chart;
239
240     }
241
242     /**
243      * Creates and returns a sample stacked horizontal bar chart.
244      *
245      * @return a sample stacked horizontal bar chart.
246      */

247     public JFreeChart createStackedHorizontalBarChart() {
248
249         // create a default chart based on some sample data...
250
String JavaDoc title = resources.getString("bar.horizontal-stacked.title");
251         String JavaDoc domain = resources.getString("bar.horizontal-stacked.domain");
252         String JavaDoc range = resources.getString("bar.horizontal-stacked.range");
253
254         CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
255         JFreeChart chart = ChartFactory.createStackedBarChart(title, domain, range,
256                                                               data,
257                                                               PlotOrientation.HORIZONTAL,
258                                                               true,
259                                                               true,
260                                                               false);
261
262         // then customise it a little...
263
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.blue));
264         return chart;
265
266     }
267
268     /**
269      * Creates and returns a sample vertical bar chart.
270      *
271      * @return a sample vertical bar chart.
272      */

273     public JFreeChart createVerticalBarChart() {
274
275         String JavaDoc title = resources.getString("bar.vertical.title");
276         String JavaDoc domain = resources.getString("bar.vertical.domain");
277         String JavaDoc range = resources.getString("bar.vertical.range");
278
279         CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
280         JFreeChart chart = ChartFactory.createBarChart(title, domain, range, data,
281                                                        PlotOrientation.VERTICAL,
282                                                        true,
283                                                        true,
284                                                        false);
285
286         // then customise it a little...
287
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.red));
288         CategoryPlot plot = (CategoryPlot) chart.getPlot();
289         plot.setForegroundAlpha(0.9f);
290         NumberAxis verticalAxis = (NumberAxis) plot.getRangeAxis();
291         verticalAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
292         return chart;
293     }
294
295     /**
296      * Creates and returns a sample vertical 3D bar chart.
297      *
298      * @return a sample vertical 3D bar chart.
299      */

300     public JFreeChart createVertical3DBarChart() {
301
302         // create a default chart based on some sample data...
303
String JavaDoc title = resources.getString("bar.vertical3D.title");
304         String JavaDoc domain = resources.getString("bar.vertical3D.domain");
305         String JavaDoc range = resources.getString("bar.vertical3D.range");
306
307         CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
308         JFreeChart chart = ChartFactory.createBarChart3D(
309             title,
310             domain,
311             range, data,
312             PlotOrientation.VERTICAL,
313             true,
314             true,
315             false
316         );
317
318         // then customise it a little...
319
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.blue));
320         CategoryPlot plot = (CategoryPlot) chart.getPlot();
321         plot.setForegroundAlpha(0.75f);
322         return chart;
323
324     }
325
326     /**
327      * Creates and returns a sample stacked vertical bar chart.
328      *
329      * @return a sample stacked vertical bar chart.
330      */

331     public JFreeChart createVerticalStackedBarChart() {
332
333         // create a default chart based on some sample data...
334
String JavaDoc title = resources.getString("bar.vertical-stacked.title");
335         String JavaDoc domain = resources.getString("bar.vertical-stacked.domain");
336         String JavaDoc range = resources.getString("bar.vertical-stacked.range");
337
338         CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
339         JFreeChart chart
340             = ChartFactory.createStackedBarChart(title, domain, range, data,
341                                                  PlotOrientation.VERTICAL,
342                                                  true,
343                                                  true,
344                                                  false);
345
346         // then customise it a little...
347
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.red));
348         return chart;
349
350     }
351
352     /**
353      * Creates and returns a sample stacked vertical 3D bar chart.
354      *
355      * @return a sample stacked vertical 3D bar chart.
356      */

357     public JFreeChart createVerticalStacked3DBarChart() {
358
359         // create a default chart based on some sample data...
360
String JavaDoc title = resources.getString("bar.vertical-stacked3D.title");
361         String JavaDoc domain = resources.getString("bar.vertical-stacked3D.domain");
362         String JavaDoc range = resources.getString("bar.vertical-stacked3D.range");
363         CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
364         JFreeChart chart = ChartFactory.createStackedBarChart3D(title, domain, range, data,
365                                                                 PlotOrientation.VERTICAL,
366                                                                 true, true, false);
367
368         // then customise it a little...
369
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.red));
370         return chart;
371
372     }
373
374     /**
375      * Creates and returns a sample pie chart.
376      *
377      * @return a sample pie chart.
378      */

379     public JFreeChart createPieChartOne() {
380
381         // create a default chart based on some sample data...
382
String JavaDoc title = resources.getString("pie.pie1.title");
383         CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
384         PieDataset extracted = DatasetUtilities.createPieDatasetForRow(data, 0);
385         JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false);
386
387         // then customise it a little...
388
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.orange));
389         PiePlot plot = (PiePlot) chart.getPlot();
390         plot.setCircular(false);
391         // make section 1 explode by 100%...
392
plot.setRadius(0.60);
393         plot.setExplodePercent(1, 1.00);
394         return chart;
395
396     }
397
398     /**
399      * Creates and returns a sample pie chart.
400      *
401      * @return a sample pie chart.
402      */

403     public JFreeChart createPieChartTwo() {
404
405         // create a default chart based on some sample data...
406
String JavaDoc title = resources.getString("pie.pie2.title");
407         CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
408         Comparable JavaDoc category = (Comparable JavaDoc) data.getColumnKeys().get(1);
409         PieDataset extracted = DatasetUtilities.createPieDatasetForColumn(data, category);
410         JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false);
411
412         // then customise it a little...
413
chart.setBackgroundPaint(Color.lightGray);
414         PiePlot pie = (PiePlot) chart.getPlot();
415         pie.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS);
416         pie.setBackgroundImage(JFreeChart.INFO.getLogo());
417         pie.setBackgroundPaint(Color.white);
418         pie.setBackgroundAlpha(0.6f);
419         pie.setForegroundAlpha(0.75f);
420         return chart;
421
422     }
423
424     /**
425      * Creates and returns a sample XY plot.
426      *
427      * @return a sample XY plot.
428      */

429     public JFreeChart createXYPlot() {
430
431         // create a default chart based on some sample data...
432
String JavaDoc title = resources.getString("xyplot.sample1.title");
433         String JavaDoc domain = resources.getString("xyplot.sample1.domain");
434         String JavaDoc range = resources.getString("xyplot.sample1.range");
435         XYDataset data = DemoDatasetFactory.createSampleXYDataset();
436         JFreeChart chart = ChartFactory.createXYLineChart(
437             title,
438             domain, range, data,
439             PlotOrientation.VERTICAL,
440             true,
441             true,
442             false
443         );
444
445         // then customise it a little...
446
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.green));
447         return chart;
448
449     }
450
451     /**
452      * Creates and returns a sample time series chart.
453      *
454      * @return a sample time series chart.
455      */

456     public JFreeChart createTimeSeries1Chart() {
457
458         // create a default chart based on some sample data...
459
String JavaDoc title = resources.getString("timeseries.sample1.title");
460         String JavaDoc subtitle = resources.getString("timeseries.sample1.subtitle");
461         String JavaDoc domain = resources.getString("timeseries.sample1.domain");
462         String JavaDoc range = resources.getString("timeseries.sample1.range");
463         String JavaDoc copyrightStr = resources.getString("timeseries.sample1.copyright");
464         XYDataset data = DemoDatasetFactory.createTimeSeriesCollection3();
465         JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain, range, data,
466                                                               true,
467                                                               true,
468                                                               false);
469
470         // then customise it a little...
471
TextTitle title2 = new TextTitle(subtitle, new Font JavaDoc("SansSerif", Font.PLAIN, 12));
472         title2.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.0));
473         chart.addSubtitle(title2);
474
475         TextTitle copyright = new TextTitle(copyrightStr, new Font JavaDoc("SansSerif", Font.PLAIN, 9));
476         copyright.setPosition(TextTitle.BOTTOM);
477         copyright.setHorizontalAlignment(TextTitle.RIGHT);
478         chart.addSubtitle(copyright);
479
480         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
481         XYPlot plot = chart.getXYPlot();
482         DateAxis axis = (DateAxis) plot.getDomainAxis();
483         axis.setVerticalTickLabels(true);
484         return chart;
485
486     }
487
488     /**
489      * Creates and returns a sample time series chart.
490      *
491      * @return a sample time series chart.
492      */

493     public JFreeChart createTimeSeries2Chart() {
494
495         // create a default chart based on some sample data...
496
String JavaDoc title = resources.getString("timeseries.sample2.title");
497         String JavaDoc subtitleStr = resources.getString("timeseries.sample2.subtitle");
498         String JavaDoc domain = resources.getString("timeseries.sample2.domain");
499         String JavaDoc range = resources.getString("timeseries.sample2.range");
500         XYDataset data = DemoDatasetFactory.createTimeSeriesCollection4();
501         JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain, range, data,
502                                                               true, true, false);
503
504         // then customise it a little...
505
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
506         chart.addSubtitle(subtitle);
507         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
508         XYPlot plot = chart.getXYPlot();
509         LogarithmicAxis rangeAxis = new LogarithmicAxis(range);
510         plot.setRangeAxis(rangeAxis);
511         return chart;
512
513     }
514
515     /**
516      * Creates and returns a sample time series chart.
517      *
518      * @return a sample time series chart.
519      */

520     public JFreeChart createTimeSeriesWithMAChart() {
521
522         // create a default chart based on some sample data...
523
String JavaDoc title = resources.getString("timeseries.sample3.title");
524         String JavaDoc domain = resources.getString("timeseries.sample3.domain");
525         String JavaDoc range = resources.getString("timeseries.sample3.range");
526         String JavaDoc subtitleStr = resources.getString("timeseries.sample3.subtitle");
527         TimeSeries jpy = DemoDatasetFactory.createJPYTimeSeries();
528         TimeSeries mav = MovingAverage.createMovingAverage(jpy, "30 Day Moving Average", 30, 30);
529         TimeSeriesCollection dataset = new TimeSeriesCollection();
530         dataset.addSeries(jpy);
531         dataset.addSeries(mav);
532         JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain, range, dataset,
533                                                               true,
534                                                               true,
535                                                               false);
536
537         // then customise it a little...
538
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
539         chart.addSubtitle(subtitle);
540         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
541         return chart;
542
543     }
544
545     /**
546      * Displays a vertical bar chart in its own frame.
547      *
548      * @return a high low chart.
549      */

550     public JFreeChart createHighLowChart() {
551
552         // create a default chart based on some sample data...
553
String JavaDoc title = resources.getString("timeseries.highlow.title");
554         String JavaDoc domain = resources.getString("timeseries.highlow.domain");
555         String JavaDoc range = resources.getString("timeseries.highlow.range");
556         String JavaDoc subtitleStr = resources.getString("timeseries.highlow.subtitle");
557         HighLowDataset data = DemoDatasetFactory.createHighLowDataset();
558         JFreeChart chart = ChartFactory.createHighLowChart(title, domain, range, data, true);
559
560         // then customise it a little...
561
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
562         chart.addSubtitle(subtitle);
563         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.magenta));
564         return chart;
565
566     }
567
568     /**
569      * Creates a candlestick chart.
570      *
571      * @return a candlestick chart.
572      */

573     public JFreeChart createCandlestickChart() {
574
575       // create a default chart based on some sample data...
576
String JavaDoc title = resources.getString("timeseries.candlestick.title");
577       String JavaDoc domain = resources.getString("timeseries.candlestick.domain");
578       String JavaDoc range = resources.getString("timeseries.candlestick.range");
579       String JavaDoc subtitleStr = resources.getString("timeseries.candlestick.subtitle");
580       HighLowDataset data = DemoDatasetFactory.createHighLowDataset();
581       JFreeChart chart = ChartFactory.createCandlestickChart(title, domain, range, data, false);
582
583       // then customise it a little...
584
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
585       chart.addSubtitle(subtitle);
586       chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.green));
587       return chart;
588
589     }
590
591     /**
592      * Creates and returns a sample signal chart.
593      *
594      * @return a sample chart.
595      */

596     public JFreeChart createSignalChart() {
597
598         // create a default chart based on some sample data...
599
String JavaDoc title = resources.getString("timeseries.signal.title");
600         String JavaDoc domain = resources.getString("timeseries.signal.domain");
601         String JavaDoc range = resources.getString("timeseries.signal.range");
602         String JavaDoc subtitleStr = resources.getString("timeseries.signal.subtitle");
603         SignalsDataset data = DemoDatasetFactory.createSampleSignalDataset();
604         JFreeChart chart = ChartFactory.createSignalChart(title, domain, range, data, true);
605
606         // then customise it a little...
607
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
608         chart.addSubtitle(subtitle);
609         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
610         return chart;
611
612     }
613
614     /**
615      * Creates and returns a sample thermometer chart.
616      *
617      * @return a sample thermometer chart.
618      */

619     public JFreeChart createThermometerChart() {
620
621         // create a default chart based on some sample data...
622
String JavaDoc title = resources.getString("meter.thermo.title");
623         String JavaDoc subtitleStr = resources.getString("meter.thermo.subtitle");
624         String JavaDoc units = resources.getString("meter.thermo.units");
625
626         DefaultValueDataset data = new DefaultValueDataset(new Double JavaDoc(34.0));
627         ThermometerPlot plot = new ThermometerPlot(data);
628         plot.setUnits(units);
629         JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
630
631         // then customise it a little...
632
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
633         chart.addSubtitle(subtitle);
634         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
635         return chart;
636
637     }
638
639     /**
640      * Creates and returns a sample meter chart.
641      *
642      * @return a meter chart.
643      */

644     public JFreeChart createMeterChartCircle() {
645
646         // create a default chart based on some sample data...
647
String JavaDoc title = resources.getString("meter.meter.title");
648         String JavaDoc subtitleStr = resources.getString("meter.meter.subtitle");
649         //String units = resources.getString("meter.meter.units");
650
//DefaultMeterDataset data = DemoDatasetFactory.createMeterDataset();
651
DefaultValueDataset data = new DefaultValueDataset(50.0);
652         //data.setUnits(units);
653
MeterPlot plot = new MeterPlot(data);
654         plot.setMeterAngle(270);
655         plot.setDialShape(DialShape.CIRCLE);
656         JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
657                                           plot, false);
658
659         // then customise it a little...
660
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
661         chart.addSubtitle(subtitle);
662         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
663         return chart;
664     }
665
666     /**
667      * Creates and returns a sample meter chart.
668      *
669      * @return a meter chart.
670      */

671     public JFreeChart createMeterChartPie() {
672
673         // create a default chart based on some sample data...
674
String JavaDoc title = resources.getString("meter.meter.title");
675         String JavaDoc subtitleStr = resources.getString("meter.meter.subtitle");
676         //String units = resources.getString("meter.meter.units");
677
//DefaultMeterDataset data = DemoDatasetFactory.createMeterDataset();
678
DefaultValueDataset data = new DefaultValueDataset(50.0);
679         //data.setUnits(units);
680
MeterPlot plot = new MeterPlot(data);
681         plot.setMeterAngle(270);
682         plot.setDialShape(DialShape.PIE);
683         JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
684
685         // then customise it a little...
686
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
687         chart.addSubtitle(subtitle);
688         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
689         return chart;
690     }
691
692     /**
693      * Creates and returns a sample meter chart.
694      *
695      * @return the meter chart.
696      */

697     public JFreeChart createMeterChartChord() {
698
699         // create a default chart based on some sample data...
700
String JavaDoc title = resources.getString("meter.meter.title");
701         String JavaDoc subtitleStr = resources.getString("meter.meter.subtitle");
702         //String units = resources.getString("meter.meter.units");
703
//DefaultMeterDataset data = DemoDatasetFactory.createMeterDataset();
704
DefaultValueDataset data = new DefaultValueDataset(45.0);
705         //data.setUnits(units);
706
MeterPlot plot = new MeterPlot(data);
707         plot.setMeterAngle(270);
708         plot.setDialShape(DialShape.CHORD);
709         JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
710
711         // then customise it a little...
712
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
713         chart.addSubtitle(subtitle);
714         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
715         return chart;
716     }
717
718     /**
719      * Creates a compass chart.
720      *
721      * @return a compass chart.
722      */

723     public JFreeChart createCompassChart() {
724
725         // create a default chart based on some sample data...
726
String JavaDoc title = resources.getString("meter.compass.title");
727         String JavaDoc subtitleStr = resources.getString("meter.compass.subtitle");
728         DefaultValueDataset data = new DefaultValueDataset(new Double JavaDoc(45.0));
729
730         Plot plot = new CompassPlot(data);
731         JFreeChart chart = new JFreeChart(
732             title,
733             JFreeChart.DEFAULT_TITLE_FONT,
734             plot,
735             false
736         );
737
738         // then customise it a little...
739
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
740         chart.addSubtitle(subtitle);
741         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
742         return chart;
743     }
744
745     /**
746      * Creates and returns a sample wind plot.
747      *
748      * @return a sample wind plot.
749      */

750     public JFreeChart createWindPlot() {
751
752         // create a default chart based on some sample data...
753
String JavaDoc title = resources.getString("other.wind.title");
754         String JavaDoc domain = resources.getString("other.wind.domain");
755         String JavaDoc range = resources.getString("other.wind.range");
756         WindDataset data = DemoDatasetFactory.createWindDataset1();
757         JFreeChart chart = ChartFactory.createWindPlot(title, domain, range, data,
758                                                        true,
759                                                        false,
760                                                        false);
761
762         // then customise it a little...
763
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.green));
764         return chart;
765
766     }
767
768     /**
769      * Creates and returns a sample scatter plot.
770      *
771      * @return a sample scatter plot.
772      */

773     public JFreeChart createScatterPlot() {
774
775         // create a default chart based on some sample data...
776
String JavaDoc title = resources.getString("other.scatter.title");
777         String JavaDoc domain = resources.getString("other.scatter.domain");
778         String JavaDoc range = resources.getString("other.scatter.range");
779         XYDataset data = new SampleXYDataset2();
780         JFreeChart chart = ChartFactory.createScatterPlot(
781             title,
782             domain,
783             range,
784             data,
785             PlotOrientation.VERTICAL,
786             true,
787             true, // tooltips
788
false // urls
789
);
790
791         // then customise it a little...
792
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.green));
793
794         XYPlot plot = chart.getXYPlot();
795         plot.setDomainCrosshairVisible(true);
796         plot.setRangeCrosshairVisible(true);
797         NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
798         rangeAxis.setAutoRangeIncludesZero(false);
799         return chart;
800
801     }
802
803     /**
804      * Creates and returns a sample line chart.
805      *
806      * @return a line chart.
807      */

808     public JFreeChart createLineChart() {
809
810         // create a default chart based on some sample data...
811
String JavaDoc title = resources.getString("other.line.title");
812         String JavaDoc domain = resources.getString("other.line.domain");
813         String JavaDoc range = resources.getString("other.line.range");
814         CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
815         JFreeChart chart = ChartFactory.createLineChart(title, domain, range, data,
816                                                         PlotOrientation.VERTICAL,
817                                                         true,
818                                                         true,
819                                                         false);
820
821         // then customise it a little...
822
chart.setBackgroundImage(JFreeChart.INFO.getLogo());
823         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.green));
824
825         CategoryPlot plot = (CategoryPlot) chart.getPlot();
826         plot.setBackgroundAlpha(0.65f);
827         return chart;
828     }
829
830     /**
831      * Creates and returns a sample vertical XY bar chart.
832      *
833      * @return a sample vertical XY bar chart.
834      */

835     public JFreeChart createVerticalXYBarChart() {
836
837         // create a default chart based on some sample data...
838
String JavaDoc title = resources.getString("other.xybar.title");
839         String JavaDoc domain = resources.getString("other.xybar.domain");
840         String JavaDoc range = resources.getString("other.xybar.range");
841         TimeSeriesCollection data = DemoDatasetFactory.createTimeSeriesCollection1();
842         data.setDomainIsPointsInTime(false);
843         JFreeChart chart = ChartFactory.createXYBarChart(
844             title,
845             domain,
846             range,
847             data,
848             PlotOrientation.VERTICAL,
849             true,
850             false,
851             false
852         );
853
854         // then customise it a little...
855
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.blue));
856
857         XYItemRenderer renderer = chart.getXYPlot().getRenderer();
858         renderer.setToolTipGenerator(new TimeSeriesToolTipGenerator());
859         return chart;
860     }
861
862     /**
863      * Creates and returns a sample XY chart with null data.
864      *
865      * @return a chart.
866      */

867     public JFreeChart createNullXYPlot() {
868
869         // create a default chart based on some sample data...
870
String JavaDoc title = resources.getString("test.null.title");
871         String JavaDoc domain = resources.getString("test.null.domain");
872         String JavaDoc range = resources.getString("test.null.range");
873         XYDataset data = null;
874         JFreeChart chart = ChartFactory.createXYLineChart(
875             title, domain, range, data,
876             PlotOrientation.VERTICAL,
877             true,
878             true,
879             false
880         );
881
882         // then customise it a little...
883
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.red));
884         return chart;
885
886     }
887
888     /**
889      * Creates a sample XY plot with an empty dataset.
890      *
891      * @return a sample XY plot with an empty dataset.
892      */

893     public JFreeChart createXYPlotZeroData() {
894
895         // create a default chart based on some sample data...
896
String JavaDoc title = resources.getString("test.zero.title");
897         String JavaDoc domain = resources.getString("test.zero.domain");
898         String JavaDoc range = resources.getString("test.zero.range");
899         XYDataset data = new EmptyXYDataset();
900         JFreeChart chart = ChartFactory.createXYLineChart(
901             title, domain, range, data,
902             PlotOrientation.VERTICAL,
903             true,
904             true,
905             false
906         );
907
908         // then customise it a little...
909
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.red));
910         return chart;
911     }
912
913     /**
914      * Creates and returns a sample time series chart that will be displayed in a scroll pane.
915      *
916      * @return a sample time series chart.
917      */

918     public JFreeChart createTimeSeriesChartInScrollPane() {
919
920         // create a default chart based on some sample data...
921
String JavaDoc title = resources.getString("test.scroll.title");
922         String JavaDoc domain = resources.getString("test.scroll.domain");
923         String JavaDoc range = resources.getString("test.scroll.range");
924         String JavaDoc subtitleStr = resources.getString("test.scroll.subtitle");
925         XYDataset data = DemoDatasetFactory.createTimeSeriesCollection2();
926         JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain, range, data,
927                                                               true,
928                                                               true,
929                                                               false);
930
931         // then customise it a little...
932
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
933         chart.addSubtitle(subtitle);
934         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.gray));
935         return chart;
936
937     }
938
939     /**
940      * Creates and returns a sample bar chart with just one series.
941      *
942      * @return a sample bar chart.
943      */

944     public JFreeChart createSingleSeriesBarChart() {
945
946         // create a default chart based on some sample data...
947
String JavaDoc title = resources.getString("test.single.title");
948         String JavaDoc domain = resources.getString("test.single.domain");
949         String JavaDoc range = resources.getString("test.single.range");
950         String JavaDoc subtitle1Str = resources.getString("test.single.subtitle1");
951         String JavaDoc subtitle2Str = resources.getString("test.single.subtitle2");
952
953         CategoryDataset data = DemoDatasetFactory.createSingleSeriesCategoryDataset();
954
955         JFreeChart chart = ChartFactory.createBarChart(title, domain, range, data,
956                                                        PlotOrientation.HORIZONTAL,
957                                                        true,
958                                                        true,
959                                                        false);
960         chart.addSubtitle(new TextTitle(subtitle1Str));
961         chart.addSubtitle(new TextTitle(subtitle2Str));
962         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.red));
963         return chart;
964
965     }
966
967     /**
968      * Displays an XY chart that is periodically updated by a background thread. This is to
969      * demonstrate the event notification system that automatically updates charts as required.
970      *
971      * @return a chart.
972      */

973     public JFreeChart createDynamicXYChart() {
974
975         String JavaDoc title = resources.getString("test.dynamic.title");
976         String JavaDoc domain = resources.getString("test.dynamic.domain");
977         String JavaDoc range = resources.getString("test.dynamic.range");
978
979         SampleXYDataset data = new SampleXYDataset();
980         JFreeChart chart = ChartFactory.createXYLineChart(
981             title, domain, range, data,
982             PlotOrientation.VERTICAL,
983             true,
984             true,
985             false
986         );
987         SampleXYDatasetThread update = new SampleXYDatasetThread(data);
988
989         Thread JavaDoc thread = new Thread JavaDoc(update);
990         thread.start();
991
992         return chart;
993
994     }
995
996     /**
997      * Creates and returns a sample overlaid chart.
998      * <P>
999      * Note: with the introduction of multiple secondary datasets in JFreeChart version 0.9.10,
1000     * the overlaid chart facility has been removed. You can achieve the same results using
1001     * a regular XYPlot with multiple datasets.
1002     *
1003     * @return an overlaid chart.
1004     */

1005    public JFreeChart createOverlaidChart() {
1006
1007        // create a default chart based on some sample data...
1008
String JavaDoc title = this.resources.getString("combined.overlaid.title");
1009        String JavaDoc subtitleStr = this.resources.getString("combined.overlaid.subtitle");
1010        String JavaDoc domainAxisLabel = this.resources.getString("combined.overlaid.domain");
1011        String JavaDoc rangeAxisLabel = this.resources.getString("combined.overlaid.range");
1012
1013        // create high-low and moving average dataset
1014
HighLowDataset highLowData = DemoDatasetFactory.createHighLowDataset();
1015
1016        // make an overlaid plot
1017
ValueAxis domainAxis = new DateAxis(domainAxisLabel);
1018        NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel);
1019        rangeAxis.setAutoRangeIncludesZero(false);
1020        XYItemRenderer renderer1 = new HighLowRenderer();
1021        renderer1.setToolTipGenerator(new HighLowToolTipGenerator());
1022
1023        XYPlot plot = new XYPlot(highLowData, domainAxis, rangeAxis, renderer1);
1024
1025        // overlay a moving average dataset
1026
XYDataset maData = MovingAverage.createMovingAverage(
1027            highLowData,
1028            " (Moving Average)",
1029            5 * 24 * 60 * 60 * 1000L,
1030            5 * 24 * 60 * 60 * 1000L
1031        );
1032        plot.setSecondaryDataset(0, maData);
1033        XYItemRenderer renderer2 = new StandardXYItemRenderer();
1034        renderer2.setToolTipGenerator(new TimeSeriesToolTipGenerator("d-MMM-yyyy", "0.00"));
1035        plot.setSecondaryRenderer(0, renderer2);
1036
1037        // make the top level JFreeChart object
1038
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
1039
1040        // then customise it a little...
1041
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
1042        chart.addSubtitle(subtitle);
1043        chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
1044
1045        return chart;
1046
1047    }
1048
1049    /**
1050     * Creates a horizontally combined chart.
1051     *
1052     * @return a horizontally combined chart.
1053     */

1054    public JFreeChart createHorizontallyCombinedChart() {
1055
1056        // create a default chart based on some sample data...
1057
String JavaDoc title = this.resources.getString("combined.horizontal.title");
1058        String JavaDoc subtitleStr = this.resources.getString("combined.horizontal.subtitle");
1059        String JavaDoc[] domains = this.resources.getStringArray("combined.horizontal.domains");
1060        String JavaDoc rangeAxisLabel = this.resources.getString("combined.horizontal.range");
1061
1062        TimeSeriesCollection dataset0 = new TimeSeriesCollection();
1063        TimeSeries eur = DemoDatasetFactory.createEURTimeSeries();
1064        dataset0.addSeries(eur);
1065
1066        TimeSeriesCollection dataset1 = new TimeSeriesCollection();
1067        TimeSeries mav = MovingAverage.createMovingAverage(eur, "EUR/GBP (30 Day MA)", 30, 30);
1068        dataset1.addSeries(eur);
1069        dataset1.addSeries(mav);
1070
1071        TimeSeriesCollection dataset2 = new TimeSeriesCollection();
1072        dataset2.addSeries(eur);
1073
1074        // make a combined range plot
1075
NumberAxis valueAxis = new NumberAxis(rangeAxisLabel);
1076        valueAxis.setAutoRangeIncludesZero(false); // override default
1077
CombinedRangeXYPlot parent = new CombinedRangeXYPlot(valueAxis);
1078        parent.setRenderer(new StandardXYItemRenderer());
1079
1080        // add subplots
1081
int[] weight = {1, 1, 1}; // controls space assigned to each subplot
1082

1083        // add subplot 1...
1084
XYPlot subplot1 = new XYPlot(dataset0, new DateAxis(domains[0]), null,
1085                                     new StandardXYItemRenderer());
1086        parent.add(subplot1, weight[0]);
1087
1088        // add subplot 2...
1089
XYPlot subplot2 = new XYPlot(dataset1, new DateAxis(domains[1]), null,
1090                                     new StandardXYItemRenderer());
1091        parent.add(subplot2, weight[1]);
1092
1093        // add subplot 3...
1094
XYPlot subplot3 = new XYPlot(dataset2, new DateAxis(domains[2]),
1095                                     null, new XYBarRenderer(0.20));
1096        parent.add(subplot3, weight[2]);
1097
1098        // now make the top level JFreeChart
1099
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, parent, true);
1100
1101        // then customise it a little...
1102
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
1103        chart.addSubtitle(subtitle);
1104        chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
1105        return chart;
1106
1107    }
1108
1109    /**
1110     * Creates and returns a sample vertically combined chart.
1111     *
1112     * @return a sample vertically combined chart.
1113     */

1114    public JFreeChart createVerticallyCombinedChart() {
1115
1116        // create a default chart based on some sample data...
1117
String JavaDoc title = this.resources.getString("combined.vertical.title");
1118        String JavaDoc subtitleStr = this.resources.getString("combined.vertical.subtitle");
1119        String JavaDoc domain = this.resources.getString("combined.vertical.domain");
1120        String JavaDoc[] ranges = this.resources.getStringArray("combined.vertical.ranges");
1121
1122
1123        TimeSeriesCollection dataset0 = new TimeSeriesCollection();
1124        TimeSeries eur = DemoDatasetFactory.createEURTimeSeries();
1125        dataset0.addSeries(eur);
1126
1127        TimeSeriesCollection dataset1 = new TimeSeriesCollection();
1128        TimeSeries jpy = DemoDatasetFactory.createJPYTimeSeries();
1129        TimeSeries mav = MovingAverage.createMovingAverage(jpy, "JPY/GBP (30 Day MA)", 30, 30);
1130        dataset1.addSeries(jpy);
1131        dataset1.addSeries(mav);
1132
1133        XYDataset dataset2 = DemoDatasetFactory.createHighLowDataset();
1134
1135        TimeSeriesCollection dataset3 = new TimeSeriesCollection();
1136        dataset3.addSeries(eur);
1137
1138        // make one shared horizontal axis
1139
ValueAxis timeAxis = new DateAxis(domain);
1140
1141        // make a vertically CombinedPlot that will contain the sub-plots
1142
CombinedDomainXYPlot multiPlot = new CombinedDomainXYPlot(timeAxis);
1143
1144        int[] weight = {1, 1, 1, 1}; // control vertical space allocated to each sub-plot
1145

1146        // add subplot1...
1147
XYPlot subplot1 = new XYPlot(dataset0, null, new NumberAxis(ranges[0]),
1148                                     new StandardXYItemRenderer());
1149        NumberAxis range1 = (NumberAxis) subplot1.getRangeAxis();
1150        range1.setTickLabelFont(new Font JavaDoc("Monospaced", Font.PLAIN, 7));
1151        range1.setLabelFont(new Font JavaDoc("SansSerif", Font.PLAIN, 8));
1152        range1.setAutoRangeIncludesZero(false);
1153        multiPlot.add(subplot1, weight[0]);
1154
1155        // add subplot2...
1156
XYPlot subplot2 = new XYPlot(dataset1, null, new NumberAxis(ranges[1]),
1157                                     new StandardXYItemRenderer());
1158        NumberAxis range2 = (NumberAxis) subplot2.getRangeAxis();
1159        range2.setTickLabelFont(new Font JavaDoc("Monospaced", Font.PLAIN, 7));
1160        range2.setLabelFont(new Font JavaDoc("SansSerif", Font.PLAIN, 8));
1161        range2.setAutoRangeIncludesZero(false);
1162        multiPlot.add(subplot2, weight[1]);
1163
1164        // add subplot3...
1165
XYPlot subplot3 = new XYPlot(dataset2, null, new NumberAxis(ranges[2]), null);
1166        XYItemRenderer renderer3 = new HighLowRenderer();
1167        subplot3.setRenderer(renderer3);
1168        NumberAxis range3 = (NumberAxis) subplot3.getRangeAxis();
1169        range3.setTickLabelFont(new Font JavaDoc("Monospaced", Font.PLAIN, 7));
1170        range3.setLabelFont(new Font JavaDoc("SansSerif", Font.PLAIN, 8));
1171        range3.setAutoRangeIncludesZero(false);
1172        multiPlot.add(subplot3, weight[2]);
1173
1174        // add subplot4...
1175
XYPlot subplot4 = new XYPlot(dataset3, null, new NumberAxis(ranges[3]), null);
1176        XYItemRenderer renderer4 = new XYBarRenderer();
1177        subplot4.setRenderer(renderer4);
1178        NumberAxis range4 = (NumberAxis) subplot4.getRangeAxis();
1179        range4.setTickLabelFont(new Font JavaDoc("Monospaced", Font.PLAIN, 7));
1180        range4.setLabelFont(new Font JavaDoc("SansSerif", Font.PLAIN, 8));
1181        range4.setAutoRangeIncludesZero(false);
1182        multiPlot.add(subplot4, weight[3]);
1183
1184        // now make the top level JFreeChart that contains the CombinedPlot
1185
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, multiPlot, true);
1186
1187        // then customise it a little...
1188
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
1189        chart.addSubtitle(subtitle);
1190        chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
1191        return chart;
1192
1193    }
1194
1195    /**
1196     * Creates a combined and overlaid chart.
1197     * <p>
1198     * Note: from version 0.9.10, the overlaid chart is no longer supported (you can achieve
1199     * the same result using a regular XYPlot with multiple datasets and renderers).
1200     *
1201     * @return a combined and overlaid chart.
1202     */

1203    public JFreeChart createCombinedAndOverlaidChart1() {
1204
1205        // create a default chart based on some sample data...
1206
String JavaDoc title = this.resources.getString("combined.combined-overlaid.title");
1207        String JavaDoc subtitleStr = this.resources.getString("combined.combined-overlaid.subtitle");
1208        String JavaDoc domain = this.resources.getString("combined.combined-overlaid.domain");
1209        String JavaDoc[] ranges = this.resources.getStringArray("combined.combined-overlaid.ranges");
1210
1211        TimeSeries jpy = DemoDatasetFactory.createJPYTimeSeries();
1212        TimeSeries mav = MovingAverage.createMovingAverage(jpy, "30 Day Moving Average", 30, 30);
1213
1214        TimeSeriesCollection dataset0 = new TimeSeriesCollection();
1215        dataset0.addSeries(jpy);
1216
1217        TimeSeriesCollection dataset1 = new TimeSeriesCollection();
1218        dataset1.addSeries(jpy);
1219        dataset1.addSeries(mav);
1220
1221        HighLowDataset highLowDataset = DemoDatasetFactory.createHighLowDataset();
1222        XYDataset highLowDatasetMA = MovingAverage.createMovingAverage(
1223            highLowDataset,
1224            " (MA)",
1225            5 * 24 * 60 * 60 * 1000L,
1226            5 * 24 * 60 * 60 * 1000L
1227        );
1228
1229        // make one vertical axis for each (vertical) chart
1230
NumberAxis[] valueAxis = new NumberAxis[3];
1231        for (int i = 0; i < valueAxis.length; i++) {
1232            valueAxis[i] = new NumberAxis(ranges[i]);
1233            if (i <= 1) {
1234                valueAxis[i].setAutoRangeIncludesZero(false); // override default
1235
}
1236        }
1237
1238        // create CombinedPlot...
1239
CombinedDomainXYPlot parent = new CombinedDomainXYPlot(new DateAxis(domain));
1240
1241        int[] weight = {1, 2, 2};
1242
1243        // add subplot1...
1244
XYItemRenderer renderer1 = new StandardXYItemRenderer();
1245        XYPlot subplot1 = new XYPlot(dataset0, null, new NumberAxis(ranges[0]), renderer1);
1246        NumberAxis axis1 = (NumberAxis) subplot1.getRangeAxis();
1247        axis1.setTickLabelFont(new Font JavaDoc("Monospaced", Font.PLAIN, 7));
1248        axis1.setLabelFont(new Font JavaDoc("SansSerif", Font.PLAIN, 8));
1249        axis1.setAutoRangeIncludesZero(false);
1250        parent.add(subplot1, weight[0]);
1251
1252        // add subplot2 (an overlaid plot)...
1253
XYPlot subplot2 = new XYPlot(dataset0, null, new NumberAxis(ranges[1]),
1254                                     new StandardXYItemRenderer());
1255        NumberAxis axis2 = (NumberAxis) subplot2.getRangeAxis();
1256        axis2.setTickLabelFont(new Font JavaDoc("Monospaced", Font.PLAIN, 7));
1257        axis2.setLabelFont(new Font JavaDoc("SansSerif", Font.PLAIN, 8));
1258        axis2.setAutoRangeIncludesZero(false);
1259        subplot2.setSecondaryDataset(0, dataset1);
1260        subplot2.setSecondaryRenderer(0, new StandardXYItemRenderer());
1261
1262        parent.add(subplot2, weight[1]);
1263
1264        // add subplot3 (an overlaid plot)...
1265
XYItemRenderer renderer3 = new HighLowRenderer();
1266        XYPlot subplot3 = new XYPlot(highLowDataset, null, new NumberAxis(ranges[2]), renderer3);
1267        NumberAxis axis3 = (NumberAxis) subplot3.getRangeAxis();
1268        axis3.setTickLabelFont(new Font JavaDoc("Monospaced", Font.PLAIN, 7));
1269        axis3.setLabelFont(new Font JavaDoc("SansSerif", Font.PLAIN, 8));
1270        axis3.setAutoRangeIncludesZero(false);
1271        subplot3.setSecondaryDataset(0, highLowDatasetMA);
1272        subplot3.setSecondaryRenderer(0, new StandardXYItemRenderer());
1273
1274        parent.add(subplot3, weight[2]);
1275
1276        // now create the master JFreeChart object
1277
JFreeChart chart = new JFreeChart(
1278            title,
1279            new Font JavaDoc("SansSerif", Font.BOLD, 12),
1280            parent,
1281            true
1282        );
1283
1284        // then customise it a little...
1285
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 10));
1286        chart.addSubtitle(subtitle);
1287        chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
1288        return chart;
1289
1290    }
1291
1292    /**
1293     * Displays an XY chart that is periodically updated by a background thread. This is to
1294     * demonstrate the event notification system that automatically updates charts as required.
1295     *
1296     * @return a chart.
1297     */

1298    public JFreeChart createCombinedAndOverlaidDynamicXYChart() {
1299
1300        // chart title and axis labels...
1301
String JavaDoc title = this.resources.getString("combined.dynamic.title");
1302        String JavaDoc subtitleStr = this.resources.getString("combined.dynamic.subtitle");
1303        String JavaDoc domainAxisLabel = this.resources.getString("combined.dynamic.domain");
1304        String JavaDoc[] ranges = this.resources.getStringArray("combined.dynamic.ranges");
1305
1306        // setup sample base 2-series dataset
1307
SampleXYDataset data = new SampleXYDataset();
1308
1309        // create some SubSeriesDatasets and CombinedDatasets to test events
1310
XYDataset series0 = new SubSeriesDataset(data, 0);
1311        XYDataset series1 = new SubSeriesDataset(data, 1);
1312
1313        CombinedDataset combinedData = new CombinedDataset();
1314        combinedData.add(series0);
1315        combinedData.add(series1);
1316
1317        // create common time axis
1318
NumberAxis timeAxis = new NumberAxis(domainAxisLabel);
1319        timeAxis.setTickMarksVisible(true);
1320        timeAxis.setAutoRangeIncludesZero(false);
1321
1322        // make one vertical axis for each (vertical) chart
1323
NumberAxis[] valueAxis = new NumberAxis[4];
1324        for (int i = 0; i < valueAxis.length; i++) {
1325            valueAxis[i] = new NumberAxis(ranges[i]);
1326            valueAxis[i].setAutoRangeIncludesZero(false);
1327        }
1328
1329        CombinedDomainXYPlot plot = new CombinedDomainXYPlot(timeAxis);
1330
1331        // add subplot1...
1332
XYItemRenderer renderer0 = new StandardXYItemRenderer();
1333        XYPlot subplot0 = new XYPlot(series0, null, valueAxis[0], renderer0);
1334        plot.add(subplot0, 1);
1335
1336        // add subplot2...
1337
XYItemRenderer renderer1 = new StandardXYItemRenderer();
1338        XYPlot subplot1 = new XYPlot(series1, null, valueAxis[1], renderer1);
1339        plot.add(subplot1, 1);
1340
1341        // add subplot3...
1342
XYPlot subplot2 = new XYPlot(series0, null, valueAxis[2], new StandardXYItemRenderer());
1343        subplot2.setSecondaryDataset(0, series1);
1344        subplot2.setSecondaryRenderer(0, new StandardXYItemRenderer());
1345        plot.add(subplot2, 1);
1346
1347        // add subplot4...
1348
XYItemRenderer renderer3 = new StandardXYItemRenderer();
1349        XYPlot subplot3 = new XYPlot(data, null, valueAxis[3], renderer3);
1350        plot.add(subplot3, 1);
1351
1352        JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
1353
1354        // then customise it a little...
1355
TextTitle subtitle = new TextTitle(subtitleStr, new Font JavaDoc("SansSerif", Font.BOLD, 12));
1356        chart.addSubtitle(subtitle);
1357        chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.cyan));
1358
1359        // setup thread to update base Dataset
1360
SampleXYDatasetThread update = new SampleXYDatasetThread(data);
1361        Thread JavaDoc thread = new Thread JavaDoc(update);
1362        thread.start();
1363
1364        return chart;
1365
1366    }
1367
1368    /**
1369     * Creates a gantt chart.
1370     *
1371     * @return a gantt chart.
1372     */

1373    public JFreeChart createGanttChart() {
1374
1375        String JavaDoc title = resources.getString("gantt.task.title");
1376        String JavaDoc domain = resources.getString("gantt.task.domain");
1377        String JavaDoc range = resources.getString("gantt.task.range");
1378
1379        IntervalCategoryDataset data = createGanttDataset1();
1380
1381        JFreeChart chart = ChartFactory.createGanttChart(
1382            title, domain, range, data,
1383            true,
1384            true,
1385            false
1386        );
1387
1388        // then customise it a little...
1389
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.blue));
1390        return chart;
1391
1392    }
1393    
1394    /**
1395     * Creates a sample dataset for a Gantt chart.
1396     *
1397     * @return The dataset.
1398     *
1399     * @deprecated Moved to the demo applications that require it.
1400     */

1401    private static IntervalCategoryDataset createGanttDataset1() {
1402
1403        TaskSeries s1 = new TaskSeries("Scheduled");
1404        s1.add(new Task("Write Proposal",
1405               new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
1406                                    date(5, Calendar.APRIL, 2001))));
1407        s1.add(new Task("Obtain Approval",
1408               new SimpleTimePeriod(date(9, Calendar.APRIL, 2001),
1409                                    date(9, Calendar.APRIL, 2001))));
1410        s1.add(new Task("Requirements Analysis",
1411               new SimpleTimePeriod(date(10, Calendar.APRIL, 2001),
1412                                    date(5, Calendar.MAY, 2001))));
1413        s1.add(new Task("Design Phase",
1414               new SimpleTimePeriod(date(6, Calendar.MAY, 2001),
1415                                    date(30, Calendar.MAY, 2001))));
1416        s1.add(new Task("Design Signoff",
1417               new SimpleTimePeriod(date(2, Calendar.JUNE, 2001),
1418                                    date(2, Calendar.JUNE, 2001))));
1419        s1.add(new Task("Alpha Implementation",
1420               new SimpleTimePeriod(date(3, Calendar.JUNE, 2001),
1421                                    date(31, Calendar.JULY, 2001))));
1422        s1.add(new Task("Design Review",
1423               new SimpleTimePeriod(date(1, Calendar.AUGUST, 2001),
1424                                    date(8, Calendar.AUGUST, 2001))));
1425        s1.add(new Task("Revised Design Signoff",
1426               new SimpleTimePeriod(date(10, Calendar.AUGUST, 2001),
1427                                    date(10, Calendar.AUGUST, 2001))));
1428        s1.add(new Task("Beta Implementation",
1429               new SimpleTimePeriod(date(12, Calendar.AUGUST, 2001),
1430                                    date(12, Calendar.SEPTEMBER, 2001))));
1431        s1.add(new Task("Testing",
1432               new SimpleTimePeriod(date(13, Calendar.SEPTEMBER, 2001),
1433                                    date(31, Calendar.OCTOBER, 2001))));
1434        s1.add(new Task("Final Implementation",
1435               new SimpleTimePeriod(date(1, Calendar.NOVEMBER, 2001),
1436                                    date(15, Calendar.NOVEMBER, 2001))));
1437        s1.add(new Task("Signoff",
1438               new SimpleTimePeriod(date(28, Calendar.NOVEMBER, 2001),
1439                                    date(30, Calendar.NOVEMBER, 2001))));
1440
1441        TaskSeries s2 = new TaskSeries("Actual");
1442        s2.add(new Task("Write Proposal",
1443               new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
1444                                    date(5, Calendar.APRIL, 2001))));
1445        s2.add(new Task("Obtain Approval",
1446               new SimpleTimePeriod(date(9, Calendar.APRIL, 2001),
1447                                    date(9, Calendar.APRIL, 2001))));
1448        s2.add(new Task("Requirements Analysis",
1449               new SimpleTimePeriod(date(10, Calendar.APRIL, 2001),
1450                                    date(15, Calendar.MAY, 2001))));
1451        s2.add(new Task("Design Phase",
1452               new SimpleTimePeriod(date(15, Calendar.MAY, 2001),
1453                                    date(17, Calendar.JUNE, 2001))));
1454        s2.add(new Task("Design Signoff",
1455               new SimpleTimePeriod(date(30, Calendar.JUNE, 2001),
1456                                    date(30, Calendar.JUNE, 2001))));
1457        s2.add(new Task("Alpha Implementation",
1458               new SimpleTimePeriod(date(1, Calendar.JULY, 2001),
1459                                    date(12, Calendar.SEPTEMBER, 2001))));
1460        s2.add(new Task("Design Review",
1461               new SimpleTimePeriod(date(12, Calendar.SEPTEMBER, 2001),
1462                                    date(22, Calendar.SEPTEMBER, 2001))));
1463        s2.add(new Task("Revised Design Signoff",
1464               new SimpleTimePeriod(date(25, Calendar.SEPTEMBER, 2001),
1465                                    date(27, Calendar.SEPTEMBER, 2001))));
1466        s2.add(new Task("Beta Implementation",
1467               new SimpleTimePeriod(date(27, Calendar.SEPTEMBER, 2001),
1468                                    date(30, Calendar.OCTOBER, 2001))));
1469        s2.add(new Task("Testing",
1470               new SimpleTimePeriod(date(31, Calendar.OCTOBER, 2001),
1471                                    date(17, Calendar.NOVEMBER, 2001))));
1472        s2.add(new Task("Final Implementation",
1473               new SimpleTimePeriod(date(18, Calendar.NOVEMBER, 2001),
1474                                    date(5, Calendar.DECEMBER, 2001))));
1475        s2.add(new Task("Signoff",
1476               new SimpleTimePeriod(date(10, Calendar.DECEMBER, 2001),
1477                                    date(11, Calendar.DECEMBER, 2001))));
1478
1479        TaskSeriesCollection collection = new TaskSeriesCollection();
1480        collection.add(s1);
1481        collection.add(s2);
1482
1483        return collection;
1484    }
1485
1486    /**
1487     * Utility method for creating <code>Date</code> objects.
1488     *
1489     * @param day the date.
1490     * @param month the month.
1491     * @param year the year.
1492     *
1493     * @return a date.
1494     */

1495    private static Date JavaDoc date(int day, int month, int year) {
1496
1497        Calendar JavaDoc calendar = Calendar.getInstance();
1498        calendar.set(year, month, day);
1499        Date JavaDoc result = calendar.getTime();
1500        return result;
1501
1502    }
1503
1504}
1505
Popular Tags