· 6 years ago · Dec 19, 2019, 11:22 AM
1/* ===========================================================
2 * JFreeChart : a free chart library for the Java(tm) platform
3 * ===========================================================
4 *
5 * (C) Copyright 2000-2017, by Object Refinery Limited and Contributors.
6 *
7 * Project Info: http://www.jfree.org/jfreechart/index.html
8 *
9 * This library is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 * License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 * USA.
23 *
24 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
25 * Other names may be trademarks of their respective owners.]
26 *
27 * -----------------
28 * ChartFactory.java
29 * -----------------
30 * (C) Copyright 2001-2017, by Object Refinery Limited and Contributors.
31 *
32 * Original Author: David Gilbert (for Object Refinery Limited);
33 * Contributor(s): Serge V. Grachov;
34 * Joao Guilherme Del Valle;
35 * Bill Kelemen;
36 * Jon Iles;
37 * Jelai Wang;
38 * Richard Atkinson;
39 * David Browning (for Australian Institute of Marine
40 * Science);
41 * Benoit Xhenseval;
42 *
43 * Changes
44 * -------
45 * 19-Oct-2001 : Version 1, most methods transferred from JFreeChart.java (DG);
46 * 22-Oct-2001 : Added methods to create stacked bar charts (DG);
47 * Renamed DataSource.java --> Dataset.java etc. (DG);
48 * 31-Oct-2001 : Added 3D-effect vertical bar and stacked-bar charts,
49 * contributed by Serge V. Grachov (DG);
50 * 07-Nov-2001 : Added a flag to control whether or not a legend is added to
51 * the chart (DG);
52 * 17-Nov-2001 : For pie chart, changed dataset from CategoryDataset to
53 * PieDataset (DG);
54 * 30-Nov-2001 : Removed try/catch handlers from chart creation, as the
55 * exception are now RuntimeExceptions, as suggested by Joao
56 * Guilherme Del Valle (DG);
57 * 06-Dec-2001 : Added createCombinableXXXXXCharts methods (BK);
58 * 12-Dec-2001 : Added createCandlestickChart() method (DG);
59 * 13-Dec-2001 : Updated methods for charts with new renderers (DG);
60 * 08-Jan-2002 : Added import for
61 * com.jrefinery.chart.combination.CombinedChart (DG);
62 * 31-Jan-2002 : Changed the createCombinableVerticalXYBarChart() method to use
63 * renderer (DG);
64 * 06-Feb-2002 : Added new method createWindPlot() (DG);
65 * 23-Apr-2002 : Updates to the chart and plot constructor API (DG);
66 * 21-May-2002 : Added new method createAreaChart() (JI);
67 * 06-Jun-2002 : Added new method createGanttChart() (DG);
68 * 11-Jun-2002 : Renamed createHorizontalStackedBarChart()
69 * --> createStackedHorizontalBarChart() for consistency (DG);
70 * 06-Aug-2002 : Updated Javadoc comments (DG);
71 * 21-Aug-2002 : Added createPieChart(CategoryDataset) method (DG);
72 * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
73 * 09-Oct-2002 : Added methods including tooltips and URL flags (DG);
74 * 06-Nov-2002 : Moved renderers into a separate package (DG);
75 * 18-Nov-2002 : Changed CategoryDataset to TableDataset (DG);
76 * 21-Mar-2003 : Incorporated HorizontalCategoryAxis3D, see bug id 685501 (DG);
77 * 13-May-2003 : Merged some horizontal and vertical methods (DG);
78 * 24-May-2003 : Added support for timeline in createHighLowChart (BK);
79 * 07-Jul-2003 : Added createHistogram() method contributed by Jelai Wang (DG);
80 * 27-Jul-2003 : Added createStackedAreaXYChart() method (RA);
81 * 05-Aug-2003 : added new method createBoxAndWhiskerChart (DB);
82 * 08-Sep-2003 : Changed ValueAxis API (DG);
83 * 07-Oct-2003 : Added stepped area XY chart contributed by Matthias Rose (DG);
84 * 06-Nov-2003 : Added createWaterfallChart() method (DG);
85 * 20-Nov-2003 : Set rendering order for 3D bar charts to fix overlapping
86 * problems (DG);
87 * 25-Nov-2003 : Added createWaferMapChart() method (DG);
88 * 23-Dec-2003 : Renamed createPie3DChart() --> createPieChart3D for
89 * consistency (DG);
90 * 20-Jan-2004 : Added createPolarChart() method (DG);
91 * 28-Jan-2004 : Fixed bug (882890) with axis range in
92 * createStackedXYAreaChart() method (DG);
93 * 25-Feb-2004 : Renamed XYToolTipGenerator --> XYItemLabelGenerator (DG);
94 * 11-Mar-2004 : Updated for pie chart changes (DG);
95 * 27-Apr-2004 : Added new createPieChart() method contributed by Benoit
96 * Xhenseval (see RFE 942195) (DG);
97 * 11-May-2004 : Split StandardCategoryItemLabelGenerator
98 * --> StandardCategoryToolTipGenerator and
99 * StandardCategoryLabelGenerator (DG);
100 * 06-Jan-2005 : Removed deprecated methods (DG);
101 * 27-Jan-2005 : Added new constructor to LineAndShapeRenderer (DG);
102 * 28-Feb-2005 : Added docs to createBubbleChart() method (DG);
103 * 17-Mar-2005 : Added createRingPlot() method (DG);
104 * 21-Apr-2005 : Replaced Insets with RectangleInsets (DG);
105 * 29-Nov-2005 : Removed signal chart (DG);
106 * ------------- JFREECHART 1.0.x ---------------------------------------------
107 * 26-Jan-2006 : Corrected API docs for createScatterPlot() (DG);
108 * 23-Aug-2006 : Modified createStackedXYAreaChart() to use
109 * StackedXYAreaRenderer2, because StackedXYAreaRenderer doesn't
110 * handle negative values (DG);
111 * 27-Sep-2006 : Update createPieChart() method for deprecated code (DG);
112 * 29-Nov-2006 : Update createXYBarChart() to use a time based tool tip
113 * generator is a DateAxis is requested (DG);
114 * 17-Jan-2007 : Added createBoxAndWhiskerChart() method from patch 1603937
115 * submitted by Darren Jung (DG);
116 * 10-Jul-2007 : Added new methods to create pie charts with locale for
117 * section label and tool tip formatting (DG);
118 * 14-Aug-2008 : Added ChartTheme facility (DG);
119 * 23-Oct-2008 : Check for legacy theme in setChartTheme() and reset default
120 * bar painters (DG);
121 * 20-Dec-2008 : In createStackedAreaChart(), set category margin to 0.0 (DG);
122 * 02-Jul-2013 : Use ParamChecks class (DG);
123 *
124 */
125
126package org.jfree.chart;
127
128import java.awt.Color;
129import java.awt.Font;
130import java.text.DateFormat;
131import java.text.NumberFormat;
132import java.util.Iterator;
133import java.util.List;
134import java.util.Locale;
135
136import org.jfree.chart.axis.CategoryAxis;
137import org.jfree.chart.axis.DateAxis;
138import org.jfree.chart.axis.NumberAxis;
139import org.jfree.chart.axis.ValueAxis;
140import org.jfree.chart.labels.BoxAndWhiskerToolTipGenerator;
141import org.jfree.chart.labels.HighLowItemLabelGenerator;
142import org.jfree.chart.labels.IntervalCategoryToolTipGenerator;
143import org.jfree.chart.labels.ItemLabelAnchor;
144import org.jfree.chart.labels.ItemLabelPosition;
145import org.jfree.chart.labels.PieToolTipGenerator;
146import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
147import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
148import org.jfree.chart.labels.StandardPieToolTipGenerator;
149import org.jfree.chart.labels.StandardXYToolTipGenerator;
150import org.jfree.chart.labels.StandardXYZToolTipGenerator;
151import org.jfree.chart.labels.XYToolTipGenerator;
152import org.jfree.chart.plot.CategoryPlot;
153import org.jfree.chart.plot.Marker;
154import org.jfree.chart.plot.MultiplePiePlot;
155import org.jfree.chart.plot.PiePlot;
156import org.jfree.chart.plot.PiePlot3D;
157import org.jfree.chart.plot.PlotOrientation;
158import org.jfree.chart.plot.PolarPlot;
159import org.jfree.chart.plot.RingPlot;
160import org.jfree.chart.plot.ValueMarker;
161import org.jfree.chart.plot.WaferMapPlot;
162import org.jfree.chart.plot.XYPlot;
163import org.jfree.chart.renderer.DefaultPolarItemRenderer;
164import org.jfree.chart.renderer.WaferMapRenderer;
165import org.jfree.chart.renderer.category.AreaRenderer;
166import org.jfree.chart.renderer.category.BarRenderer;
167import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
168import org.jfree.chart.renderer.category.CategoryItemRenderer;
169import org.jfree.chart.renderer.category.GanttRenderer;
170import org.jfree.chart.renderer.category.GradientBarPainter;
171import org.jfree.chart.renderer.category.LineAndShapeRenderer;
172import org.jfree.chart.renderer.category.StackedAreaRenderer;
173import org.jfree.chart.renderer.category.StackedBarRenderer;
174import org.jfree.chart.renderer.category.StandardBarPainter;
175import org.jfree.chart.renderer.category.WaterfallBarRenderer;
176import org.jfree.chart.renderer.xy.CandlestickRenderer;
177import org.jfree.chart.renderer.xy.GradientXYBarPainter;
178import org.jfree.chart.renderer.xy.HighLowRenderer;
179import org.jfree.chart.renderer.xy.StackedXYAreaRenderer2;
180import org.jfree.chart.renderer.xy.StandardXYBarPainter;
181import org.jfree.chart.renderer.xy.WindItemRenderer;
182import org.jfree.chart.renderer.xy.XYAreaRenderer;
183import org.jfree.chart.renderer.xy.XYBarRenderer;
184import org.jfree.chart.renderer.xy.XYBoxAndWhiskerRenderer;
185import org.jfree.chart.renderer.xy.XYBubbleRenderer;
186import org.jfree.chart.renderer.xy.XYItemRenderer;
187import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
188import org.jfree.chart.renderer.xy.XYStepAreaRenderer;
189import org.jfree.chart.renderer.xy.XYStepRenderer;
190import org.jfree.chart.title.TextTitle;
191import org.jfree.chart.ui.Layer;
192import org.jfree.chart.ui.RectangleEdge;
193import org.jfree.chart.ui.RectangleInsets;
194import org.jfree.chart.ui.TextAnchor;
195import org.jfree.chart.urls.PieURLGenerator;
196import org.jfree.chart.urls.StandardCategoryURLGenerator;
197import org.jfree.chart.urls.StandardPieURLGenerator;
198import org.jfree.chart.urls.StandardXYURLGenerator;
199import org.jfree.chart.urls.StandardXYZURLGenerator;
200import org.jfree.chart.urls.XYURLGenerator;
201import org.jfree.chart.util.Args;
202import org.jfree.chart.util.TableOrder;
203import org.jfree.data.category.CategoryDataset;
204import org.jfree.data.category.IntervalCategoryDataset;
205import org.jfree.data.general.DefaultPieDataset;
206import org.jfree.data.general.PieDataset;
207import org.jfree.data.general.WaferMapDataset;
208import org.jfree.data.statistics.BoxAndWhiskerCategoryDataset;
209import org.jfree.data.statistics.BoxAndWhiskerXYDataset;
210import org.jfree.data.xy.IntervalXYDataset;
211import org.jfree.data.xy.OHLCDataset;
212import org.jfree.data.xy.TableXYDataset;
213import org.jfree.data.xy.WindDataset;
214import org.jfree.data.xy.XYDataset;
215import org.jfree.data.xy.XYZDataset;
216
217/**
218 * A collection of utility methods for creating some standard charts with
219 * JFreeChart.
220 */
221public abstract class ChartFactory {
222
223 private ChartFactory() {
224 throw new IllegalStateException("Utility class");
225 }
226
227 /** The chart theme. */
228 private static ChartTheme currentTheme = new StandardChartTheme("JFree");
229
230 /**
231 * Returns the current chart theme used by the factory.
232 *
233 * @return The chart theme.
234 *
235 * @see #setChartTheme(ChartTheme)
236 * @see ChartUtils#applyCurrentTheme(JFreeChart)
237 *
238 * @since 1.0.11
239 */
240 public static ChartTheme getChartTheme() {
241 return currentTheme;
242 }
243
244 /**
245 * Sets the current chart theme. This will be applied to all new charts
246 * created via methods in this class.
247 *
248 * @param theme the theme ({@code null} not permitted).
249 *
250 * @see #getChartTheme()
251 * @see ChartUtils#applyCurrentTheme(JFreeChart)
252 *
253 * @since 1.0.11
254 */
255 public static void setChartTheme(ChartTheme theme) {
256 Args.nullNotPermitted(theme, "theme");
257 currentTheme = theme;
258
259 // here we do a check to see if the user is installing the "Legacy"
260 // theme, and reset the bar painters in that case...
261 if (theme instanceof StandardChartTheme) {
262 StandardChartTheme sct = (StandardChartTheme) theme;
263 if (sct.getName().equals("Legacy")) {
264 BarRenderer.setDefaultBarPainter(new StandardBarPainter());
265 XYBarRenderer.setDefaultBarPainter(new StandardXYBarPainter());
266 }
267 else {
268 BarRenderer.setDefaultBarPainter(new GradientBarPainter());
269 XYBarRenderer.setDefaultBarPainter(new GradientXYBarPainter());
270 }
271 }
272 }
273
274 /**
275 * Creates a pie chart with default settings.
276 * <P>
277 * The chart object returned by this method uses a {@link PiePlot} instance
278 * as the plot.
279 *
280 * @param title the chart title ({@code null} permitted).
281 * @param dataset the dataset for the chart ({@code null} permitted).
282 * @param legend a flag specifying whether or not a legend is required.
283 * @param tooltips configure chart to generate tool tips?
284 * @param locale the locale ({@code null} not permitted).
285 *
286 * @return A pie chart.
287 *
288 * @since 1.0.7
289 */
290 public static JFreeChart createPieChart(String title, PieDataset dataset,
291 boolean legend, boolean tooltips, Locale locale) {
292
293 PiePlot plot = new PiePlot(dataset);
294 plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
295 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
296 if (tooltips) {
297 plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
298 }
299 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
300 plot, legend);
301 currentTheme.apply(chart);
302 return chart;
303
304 }
305
306 /**
307 * Creates a pie chart with default settings.
308 * <P>
309 * The chart object returned by this method uses a {@link PiePlot} instance
310 * as the plot.
311 *
312 * @param title the chart title ({@code null} permitted).
313 * @param dataset the dataset for the chart ({@code null} permitted).
314 *
315 * @return A pie chart.
316 *
317 * @since 1.0.16
318 */
319 public static JFreeChart createPieChart(String title, PieDataset dataset) {
320 return createPieChart(title, dataset, true, true, false);
321 }
322
323 /**
324 * Creates a pie chart with default settings.
325 * <P>
326 * The chart object returned by this method uses a {@link PiePlot} instance
327 * as the plot.
328 *
329 * @param title the chart title ({@code null} permitted).
330 * @param dataset the dataset for the chart ({@code null} permitted).
331 * @param legend a flag specifying whether or not a legend is required.
332 * @param tooltips configure chart to generate tool tips?
333 * @param urls configure chart to generate URLs?
334 *
335 * @return A pie chart.
336 */
337 public static JFreeChart createPieChart(String title, PieDataset dataset,
338 boolean legend, boolean tooltips, boolean urls) {
339
340 PiePlot plot = new PiePlot(dataset);
341 plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
342 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
343 if (tooltips) {
344 plot.setToolTipGenerator(new StandardPieToolTipGenerator());
345 }
346 if (urls) {
347 plot.setURLGenerator(new StandardPieURLGenerator());
348 }
349 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
350 plot, legend);
351 currentTheme.apply(chart);
352 return chart;
353 }
354
355 /**
356 * Creates a pie chart with default settings that compares 2 datasets.
357 * The colour of each section will be determined by the move from the value
358 * for the same key in {@code previousDataset}. ie if value1 >
359 * value2 then the section will be in green (unless
360 * {@code greenForIncrease} is {@code false}, in which case it
361 * would be {@code red}). Each section can have a shade of red or
362 * green as the difference can be tailored between 0% (black) and
363 * percentDiffForMaxScale% (bright red/green).
364 * <p>
365 * For instance if {@code percentDiffForMaxScale} is 10 (10%), a
366 * difference of 5% will have a half shade of red/green, a difference of
367 * 10% or more will have a maximum shade/brightness of red/green.
368 * <P>
369 * The chart object returned by this method uses a {@link PiePlot} instance
370 * as the plot.
371 * <p>
372 * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit
373 * Xhenseval</a>.
374 *
375 * @param title the chart title ({@code null} permitted).
376 * @param dataset the dataset for the chart ({@code null} permitted).
377 * @param previousDataset the dataset for the last run, this will be used
378 * to compare each key in the dataset
379 * @param percentDiffForMaxScale scale goes from bright red/green to black,
380 * percentDiffForMaxScale indicate the change
381 * required to reach top scale.
382 * @param greenForIncrease an increase since previousDataset will be
383 * displayed in green (decrease red) if true.
384 * @param legend a flag specifying whether or not a legend is required.
385 * @param tooltips configure chart to generate tool tips?
386 * @param locale the locale ({@code null} not permitted).
387 * @param subTitle displays a subtitle with colour scheme if true
388 * @param showDifference create a new dataset that will show the %
389 * difference between the two datasets.
390 *
391 * @return A pie chart.
392 *
393 * @since 1.0.7
394 */
395 private static JFreeChart Duplicazione (String title, PieDataset dataset,
396 PieDataset previousDataset, int percentDiffForMaxScale,
397 boolean greenForIncrease, boolean legend, boolean tooltips,
398 Locale locale, boolean subTitle, boolean showDifference, PiePlot plot) {
399 List keys = dataset.getKeys();
400 DefaultPieDataset series = null;
401 if (showDifference) {
402 series = new DefaultPieDataset();
403 }
404
405 double colorPerPercent = 255.0 / percentDiffForMaxScale;
406 for (Iterator it = keys.iterator(); it.hasNext();) {
407 Comparable key = (Comparable) it.next();
408 Number newValue = dataset.getValue(key);
409 Number oldValue = previousDataset.getValue(key);
410
411 if (oldValue == null) {
412 if (greenForIncrease) {
413 plot.setSectionPaint(key, Color.GREEN);
414 }
415 else {
416 plot.setSectionPaint(key, Color.RED);
417 }
418 if (showDifference) {
419 assert series != null; // suppresses compiler warning
420 series.setValue(key + " (+100%)", newValue);
421 }
422 }
423 else {
424 double percentChange = (newValue.doubleValue()
425 / oldValue.doubleValue() - 1.0) * 100.0;
426 double shade
427 = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255
428 : Math.abs(percentChange) * colorPerPercent);
429 if (greenForIncrease
430 && newValue.doubleValue() > oldValue.doubleValue()
431 || !greenForIncrease && newValue.doubleValue()
432 < oldValue.doubleValue()) {
433 plot.setSectionPaint(key, new Color(0, (int) shade, 0));
434 }
435 else {
436 plot.setSectionPaint(key, new Color((int) shade, 0, 0));
437 }
438 if (showDifference) {
439 assert series != null; // suppresses compiler warning
440 series.setValue(key + " (" + (percentChange >= 0 ? "+" : "")
441 + NumberFormat.getPercentInstance().format(
442 percentChange / 100.0) + ")", newValue);
443 }
444 }
445 }
446
447 if (showDifference) {
448 plot.setDataset(series);
449 }
450
451 JFreeChart chart = new JFreeChart(title,
452 JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
453
454 if (subTitle) {
455 TextTitle subtitle = new TextTitle("Bright " + (greenForIncrease
456 ? "red" : "green") + "=change >=-" + percentDiffForMaxScale
457 + "%, Bright " + (!greenForIncrease ? "red" : "green")
458 + "=change >=+" + percentDiffForMaxScale + "%",
459 new Font("SansSerif", Font.PLAIN, 10));
460 chart.addSubtitle(subtitle);
461 }
462 currentTheme.apply(chart);
463 return chart;
464
465 }
466 public static JFreeChart createPieChart(String title, PieDataset dataset,
467 PieDataset previousDataset, int percentDiffForMaxScale,
468 boolean greenForIncrease, boolean legend, boolean tooltips,
469 Locale locale, boolean subTitle, boolean showDifference) {
470
471 PiePlot plot = new PiePlot(dataset);
472 plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
473 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
474
475 if (tooltips) {
476 plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
477 }
478
479 return Duplicazione(title, dataset, previousDataset, percentDiffForMaxScale,
480 greenForIncrease, legend, tooltips,locale, subTitle, showDifference, plot);
481 }
482
483 /**
484 * Creates a pie chart with default settings that compares 2 datasets.
485 * The colour of each section will be determined by the move from the value
486 * for the same key in {@code previousDataset}. ie if value1 >
487 * value2 then the section will be in green (unless
488 * {@code greenForIncrease} is {@code false}, in which case it
489 * would be {@code red}). Each section can have a shade of red or
490 * green as the difference can be tailored between 0% (black) and
491 * percentDiffForMaxScale% (bright red/green).
492 * <p>
493 * For instance if {@code percentDiffForMaxScale} is 10 (10%), a
494 * difference of 5% will have a half shade of red/green, a difference of
495 * 10% or more will have a maximum shade/brightness of red/green.
496 * <P>
497 * The chart object returned by this method uses a {@link PiePlot} instance
498 * as the plot.
499 * <p>
500 * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit
501 * Xhenseval</a>.
502 *
503 * @param title the chart title ({@code null} permitted).
504 * @param dataset the dataset for the chart ({@code null} permitted).
505 * @param previousDataset the dataset for the last run, this will be used
506 * to compare each key in the dataset
507 * @param percentDiffForMaxScale scale goes from bright red/green to black,
508 * percentDiffForMaxScale indicate the change
509 * required to reach top scale.
510 * @param greenForIncrease an increase since previousDataset will be
511 * displayed in green (decrease red) if true.
512 * @param legend a flag specifying whether or not a legend is required.
513 * @param tooltips configure chart to generate tool tips?
514 * @param urls configure chart to generate URLs?
515 * @param subTitle displays a subtitle with colour scheme if true
516 * @param showDifference create a new dataset that will show the %
517 * difference between the two datasets.
518 *
519 * @return A pie chart.
520 */
521 public static JFreeChart createPieChart(String title, PieDataset dataset,
522 PieDataset previousDataset, int percentDiffForMaxScale,
523 boolean greenForIncrease, boolean legend, boolean tooltips,
524 boolean urls, boolean subTitle, boolean showDifference) {
525
526 PiePlot plot = new PiePlot(dataset);
527 plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
528 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
529
530 if (tooltips) {
531 plot.setToolTipGenerator(new StandardPieToolTipGenerator());
532 }
533 if (urls) {
534 plot.setURLGenerator(new StandardPieURLGenerator());
535 }
536
537 List keys = dataset.getKeys();
538 DefaultPieDataset series = null;
539 if (showDifference) {
540 series = new DefaultPieDataset();
541 }
542
543 double colorPerPercent = 255.0 / percentDiffForMaxScale;
544 for (Iterator it = keys.iterator(); it.hasNext();) {
545 Comparable key = (Comparable) it.next();
546 Number newValue = dataset.getValue(key);
547 Number oldValue = previousDataset.getValue(key);
548
549 if (oldValue == null) {
550 if (greenForIncrease) {
551 plot.setSectionPaint(key, Color.GREEN);
552 }
553 else {
554 plot.setSectionPaint(key, Color.RED);
555 }
556 if (showDifference) {
557 assert series != null; // suppresses compiler warning
558 series.setValue(key + " (+100%)", newValue);
559 }
560 }
561 else {
562 double percentChange = (newValue.doubleValue()
563 / oldValue.doubleValue() - 1.0) * 100.0;
564 double shade
565 = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255
566 : Math.abs(percentChange) * colorPerPercent);
567 if (greenForIncrease
568 && newValue.doubleValue() > oldValue.doubleValue()
569 || !greenForIncrease && newValue.doubleValue()
570 < oldValue.doubleValue()) {
571 plot.setSectionPaint(key, new Color(0, (int) shade, 0));
572 }
573 else {
574 plot.setSectionPaint(key, new Color((int) shade, 0, 0));
575 }
576 if (showDifference) {
577 assert series != null; // suppresses compiler warning
578 series.setValue(key + " (" + (percentChange >= 0 ? "+" : "")
579 + NumberFormat.getPercentInstance().format(
580 percentChange / 100.0) + ")", newValue);
581 }
582 }
583 }
584
585 if (showDifference) {
586 plot.setDataset(series);
587 }
588
589 JFreeChart chart = new JFreeChart(title,
590 JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
591
592 if (subTitle) {
593 TextTitle subtitle = new TextTitle("Bright " + (greenForIncrease
594 ? "red" : "green") + "=change >=-" + percentDiffForMaxScale
595 + "%, Bright " + (!greenForIncrease ? "red" : "green")
596 + "=change >=+" + percentDiffForMaxScale + "%",
597 new Font("SansSerif", Font.PLAIN, 10));
598 chart.addSubtitle(subtitle);
599 }
600 currentTheme.apply(chart);
601 return chart;
602 }
603
604 /**
605 * Creates a ring chart with default settings.
606 * <P>
607 * The chart object returned by this method uses a {@link RingPlot}
608 * instance as the plot.
609 *
610 * @param title the chart title ({@code null} permitted).
611 * @param dataset the dataset for the chart ({@code null} permitted).
612 * @param legend a flag specifying whether or not a legend is required.
613 * @param tooltips configure chart to generate tool tips?
614 * @param locale the locale ({@code null} not permitted).
615 *
616 * @return A ring chart.
617 *
618 * @since 1.0.7
619 */
620 public static JFreeChart createRingChart(String title, PieDataset dataset,
621 boolean legend, boolean tooltips, Locale locale) {
622
623 RingPlot plot = new RingPlot(dataset);
624 plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
625 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
626 if (tooltips) {
627 plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
628 }
629 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
630 plot, legend);
631 currentTheme.apply(chart);
632 return chart;
633 }
634
635 /**
636 * Creates a ring chart with default settings.
637 * <P>
638 * The chart object returned by this method uses a {@link RingPlot}
639 * instance as the plot.
640 *
641 * @param title the chart title ({@code null} permitted).
642 * @param dataset the dataset for the chart ({@code null} permitted).
643 * @param legend a flag specifying whether or not a legend is required.
644 * @param tooltips configure chart to generate tool tips?
645 * @param urls configure chart to generate URLs?
646 *
647 * @return A ring chart.
648 */
649 public static JFreeChart createRingChart(String title, PieDataset dataset,
650 boolean legend, boolean tooltips, boolean urls) {
651
652 RingPlot plot = new RingPlot(dataset);
653 plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
654 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
655 if (tooltips) {
656 plot.setToolTipGenerator(new StandardPieToolTipGenerator());
657 }
658 if (urls) {
659 plot.setURLGenerator(new StandardPieURLGenerator());
660 }
661 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
662 plot, legend);
663 currentTheme.apply(chart);
664 return chart;
665
666 }
667
668 /**
669 * Creates a chart that displays multiple pie plots. The chart object
670 * returned by this method uses a {@link MultiplePiePlot} instance as the
671 * plot.
672 *
673 * @param title the chart title ({@code null} permitted).
674 * @param dataset the dataset ({@code null} permitted).
675 * @param order the order that the data is extracted (by row or by column)
676 * ({@code null} not permitted).
677 * @param legend include a legend?
678 * @param tooltips generate tooltips?
679 * @param urls generate URLs?
680 *
681 * @return A chart.
682 */
683 public static JFreeChart createMultiplePieChart(String title,
684 CategoryDataset dataset, TableOrder order, boolean legend,
685 boolean tooltips, boolean urls) {
686
687 Args.nullNotPermitted(order, "order");
688 MultiplePiePlot plot = new MultiplePiePlot(dataset);
689 plot.setDataExtractOrder(order);
690 plot.setBackgroundPaint(null);
691 plot.setOutlineStroke(null);
692
693 if (tooltips) {
694 PieToolTipGenerator tooltipGenerator
695 = new StandardPieToolTipGenerator();
696 PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
697 pp.setToolTipGenerator(tooltipGenerator);
698 }
699
700 if (urls) {
701 PieURLGenerator urlGenerator = new StandardPieURLGenerator();
702 PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
703 pp.setURLGenerator(urlGenerator);
704 }
705
706 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
707 plot, legend);
708 currentTheme.apply(chart);
709 return chart;
710
711 }
712
713 /**
714 * Creates a 3D pie chart using the specified dataset. The chart object
715 * returned by this method uses a {@link PiePlot3D} instance as the
716 * plot.
717 *
718 * @param title the chart title ({@code null} permitted).
719 * @param dataset the dataset for the chart ({@code null} permitted).
720 * @param legend a flag specifying whether or not a legend is required.
721 * @param tooltips configure chart to generate tool tips?
722 * @param locale the locale ({@code null} not permitted).
723 *
724 * @return A pie chart.
725 *
726 * @since 1.0.7
727 */
728 public static JFreeChart createPieChart3D(String title, PieDataset dataset,
729 boolean legend, boolean tooltips, Locale locale) {
730
731 Args.nullNotPermitted(locale, "locale");
732 PiePlot3D plot = new PiePlot3D(dataset);
733 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
734 if (tooltips) {
735 plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
736 }
737 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
738 plot, legend);
739 currentTheme.apply(chart);
740 return chart;
741
742 }
743
744 /**
745 * Creates a 3D pie chart using the specified dataset. The chart object
746 * returned by this method uses a {@link PiePlot3D} instance as the
747 * plot.
748 *
749 * @param title the chart title ({@code null} permitted).
750 * @param dataset the dataset for the chart ({@code null} permitted).
751 *
752 * @return A pie chart.
753 *
754 * @since 1.0.16
755 */
756 public static JFreeChart createPieChart3D(String title,
757 PieDataset dataset) {
758 return createPieChart3D(title, dataset, true, true, false);
759 }
760
761 /**
762 * Creates a 3D pie chart using the specified dataset. The chart object
763 * returned by this method uses a {@link PiePlot3D} instance as the
764 * plot.
765 *
766 * @param title the chart title ({@code null} permitted).
767 * @param dataset the dataset for the chart ({@code null} permitted).
768 * @param legend a flag specifying whether or not a legend is required.
769 * @param tooltips configure chart to generate tool tips?
770 * @param urls configure chart to generate URLs?
771 *
772 * @return A pie chart.
773 */
774 public static JFreeChart createPieChart3D(String title, PieDataset dataset,
775 boolean legend, boolean tooltips, boolean urls) {
776
777 PiePlot3D plot = new PiePlot3D(dataset);
778 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
779 if (tooltips) {
780 plot.setToolTipGenerator(new StandardPieToolTipGenerator());
781 }
782 if (urls) {
783 plot.setURLGenerator(new StandardPieURLGenerator());
784 }
785 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
786 plot, legend);
787 currentTheme.apply(chart);
788 return chart;
789
790 }
791
792 /**
793 * Creates a chart that displays multiple pie plots. The chart object
794 * returned by this method uses a {@link MultiplePiePlot} instance as the
795 * plot.
796 *
797 * @param title the chart title ({@code null} permitted).
798 * @param dataset the dataset ({@code null} permitted).
799 * @param order the order that the data is extracted (by row or by column)
800 * ({@code null} not permitted).
801 * @param legend include a legend?
802 * @param tooltips generate tooltips?
803 * @param urls generate URLs?
804 *
805 * @return A chart.
806 */
807 public static JFreeChart createMultiplePieChart3D(String title,
808 CategoryDataset dataset, TableOrder order, boolean legend,
809 boolean tooltips, boolean urls) {
810
811 Args.nullNotPermitted(order, "order");
812 MultiplePiePlot plot = new MultiplePiePlot(dataset);
813 plot.setDataExtractOrder(order);
814 plot.setBackgroundPaint(null);
815 plot.setOutlineStroke(null);
816
817 JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));
818 TextTitle seriesTitle = new TextTitle("Series Title",
819 new Font("SansSerif", Font.BOLD, 12));
820 seriesTitle.setPosition(RectangleEdge.BOTTOM);
821 pieChart.setTitle(seriesTitle);
822 pieChart.removeLegend();
823 pieChart.setBackgroundPaint(null);
824 plot.setPieChart(pieChart);
825
826 if (tooltips) {
827 PieToolTipGenerator tooltipGenerator
828 = new StandardPieToolTipGenerator();
829 PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
830 pp.setToolTipGenerator(tooltipGenerator);
831 }
832
833 if (urls) {
834 PieURLGenerator urlGenerator = new StandardPieURLGenerator();
835 PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
836 pp.setURLGenerator(urlGenerator);
837 }
838
839 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
840 plot, legend);
841 currentTheme.apply(chart);
842 return chart;
843
844 }
845
846 /**
847 * Creates a bar chart with a vertical orientation. The chart object
848 * returned by this method uses a {@link CategoryPlot} instance as the
849 * plot, with a {@link CategoryAxis} for the domain axis, a
850 * {@link NumberAxis} as the range axis, and a {@link BarRenderer} as the
851 * renderer.
852 *
853 * @param title the chart title ({@code null} permitted).
854 * @param categoryAxisLabel the label for the category axis
855 * ({@code null} permitted).
856 * @param valueAxisLabel the label for the value axis
857 * ({@code null} permitted).
858 * @param dataset the dataset for the chart ({@code null} permitted).
859 *
860 * @return A bar chart.
861 *
862 * @since 1.0.16
863 */
864 public static JFreeChart createBarChart(String title,
865 String categoryAxisLabel, String valueAxisLabel,
866 CategoryDataset dataset) {
867 return createBarChart(title, categoryAxisLabel, valueAxisLabel, dataset,
868 PlotOrientation.VERTICAL, true, true, false);
869 }
870
871 /**
872 * Creates a bar chart. The chart object returned by this method uses a
873 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis}
874 * for the domain axis, a {@link NumberAxis} as the range axis, and a
875 * {@link BarRenderer} as the renderer.
876 *
877 * @param title the chart title ({@code null} permitted).
878 * @param categoryAxisLabel the label for the category axis
879 * ({@code null} permitted).
880 * @param valueAxisLabel the label for the value axis
881 * ({@code null} permitted).
882 * @param dataset the dataset for the chart ({@code null} permitted).
883 * @param orientation the plot orientation (horizontal or vertical)
884 * ({@code null} not permitted).
885 * @param legend a flag specifying whether or not a legend is required.
886 * @param tooltips configure chart to generate tool tips?
887 * @param urls configure chart to generate URLs?
888 *
889 * @return A bar chart.
890 */
891 public static JFreeChart createBarChart(String title,
892 String categoryAxisLabel, String valueAxisLabel,
893 CategoryDataset dataset, PlotOrientation orientation,
894 boolean legend, boolean tooltips, boolean urls) {
895
896 Args.nullNotPermitted(orientation, "orientation");
897 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
898 ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
899
900 BarRenderer renderer = new BarRenderer();
901 if (orientation == PlotOrientation.HORIZONTAL) {
902 ItemLabelPosition position1 = new ItemLabelPosition(
903 ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
904 renderer.setDefaultPositiveItemLabelPosition(position1);
905 ItemLabelPosition position2 = new ItemLabelPosition(
906 ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);
907 renderer.setDefaultNegativeItemLabelPosition(position2);
908 } else if (orientation == PlotOrientation.VERTICAL) {
909 ItemLabelPosition position1 = new ItemLabelPosition(
910 ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
911 renderer.setDefaultPositiveItemLabelPosition(position1);
912 ItemLabelPosition position2 = new ItemLabelPosition(
913 ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
914 renderer.setDefaultNegativeItemLabelPosition(position2);
915 }
916 if (tooltips) {
917 renderer.setDefaultToolTipGenerator(
918 new StandardCategoryToolTipGenerator());
919 }
920 if (urls) {
921 renderer.setDefaultItemURLGenerator(
922 new StandardCategoryURLGenerator());
923 }
924
925 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
926 renderer);
927 plot.setOrientation(orientation);
928 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
929 plot, legend);
930 currentTheme.apply(chart);
931 return chart;
932
933 }
934
935 /**
936 * Creates a stacked bar chart with default settings. The chart object
937 * returned by this method uses a {@link CategoryPlot} instance as the
938 * plot, with a {@link CategoryAxis} for the domain axis, a
939 * {@link NumberAxis} as the range axis, and a {@link StackedBarRenderer}
940 * as the renderer.
941 *
942 * @param title the chart title ({@code null} permitted).
943 * @param domainAxisLabel the label for the category axis
944 * ({@code null} permitted).
945 * @param rangeAxisLabel the label for the value axis
946 * ({@code null} permitted).
947 * @param dataset the dataset for the chart ({@code null} permitted).
948 *
949 * @return A stacked bar chart.
950 *
951 * @since 1.0.16
952 */
953 public static JFreeChart createStackedBarChart(String title,
954 String domainAxisLabel, String rangeAxisLabel,
955 CategoryDataset dataset) {
956 return createStackedBarChart(title, domainAxisLabel, rangeAxisLabel,
957 dataset, PlotOrientation.VERTICAL, true, true, false);
958 }
959
960 /**
961 * Creates a stacked bar chart with default settings. The chart object
962 * returned by this method uses a {@link CategoryPlot} instance as the
963 * plot, with a {@link CategoryAxis} for the domain axis, a
964 * {@link NumberAxis} as the range axis, and a {@link StackedBarRenderer}
965 * as the renderer.
966 *
967 * @param title the chart title ({@code null} permitted).
968 * @param domainAxisLabel the label for the category axis
969 * ({@code null} permitted).
970 * @param rangeAxisLabel the label for the value axis
971 * ({@code null} permitted).
972 * @param dataset the dataset for the chart ({@code null} permitted).
973 * @param orientation the orientation of the chart (horizontal or
974 * vertical) ({@code null} not permitted).
975 * @param legend a flag specifying whether or not a legend is required.
976 * @param tooltips configure chart to generate tool tips?
977 * @param urls configure chart to generate URLs?
978 *
979 * @return A stacked bar chart.
980 */
981 public static JFreeChart createStackedBarChart(String title,
982 String domainAxisLabel, String rangeAxisLabel,
983 CategoryDataset dataset, PlotOrientation orientation,
984 boolean legend, boolean tooltips, boolean urls) {
985
986 Args.nullNotPermitted(orientation, "orientation");
987
988 CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel);
989 ValueAxis valueAxis = new NumberAxis(rangeAxisLabel);
990
991 StackedBarRenderer renderer = new StackedBarRenderer();
992 if (tooltips) {
993 renderer.setDefaultToolTipGenerator(
994 new StandardCategoryToolTipGenerator());
995 }
996 if (urls) {
997 renderer.setDefaultItemURLGenerator(
998 new StandardCategoryURLGenerator());
999 }
1000
1001 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
1002 renderer);
1003 plot.setOrientation(orientation);
1004 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1005 plot, legend);
1006 currentTheme.apply(chart);
1007 return chart;
1008
1009 }
1010
1011 /**
1012 * Creates an area chart with default settings. The chart object returned
1013 * by this method uses a {@link CategoryPlot} instance as the plot, with a
1014 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the
1015 * range axis, and an {@link AreaRenderer} as the renderer.
1016 *
1017 * @param title the chart title ({@code null} permitted).
1018 * @param categoryAxisLabel the label for the category axis
1019 * ({@code null} permitted).
1020 * @param valueAxisLabel the label for the value axis ({@code null}
1021 * permitted).
1022 * @param dataset the dataset for the chart ({@code null} permitted).
1023 *
1024 * @return An area chart.
1025 *
1026 * @since 1.0.16
1027 */
1028 public static JFreeChart createAreaChart(String title,
1029 String categoryAxisLabel, String valueAxisLabel,
1030 CategoryDataset dataset) {
1031 return createAreaChart(title, categoryAxisLabel, valueAxisLabel,
1032 dataset, PlotOrientation.VERTICAL, true, true, false);
1033 }
1034
1035 /**
1036 * Creates an area chart with default settings. The chart object returned
1037 * by this method uses a {@link CategoryPlot} instance as the plot, with a
1038 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the
1039 * range axis, and an {@link AreaRenderer} as the renderer.
1040 *
1041 * @param title the chart title ({@code null} permitted).
1042 * @param categoryAxisLabel the label for the category axis
1043 * ({@code null} permitted).
1044 * @param valueAxisLabel the label for the value axis ({@code null}
1045 * permitted).
1046 * @param dataset the dataset for the chart ({@code null} permitted).
1047 * @param orientation the plot orientation ({@code null} not
1048 * permitted).
1049 * @param legend a flag specifying whether or not a legend is required.
1050 * @param tooltips configure chart to generate tool tips?
1051 * @param urls configure chart to generate URLs?
1052 *
1053 * @return An area chart.
1054 */
1055 public static JFreeChart createAreaChart(String title,
1056 String categoryAxisLabel, String valueAxisLabel,
1057 CategoryDataset dataset, PlotOrientation orientation,
1058 boolean legend, boolean tooltips, boolean urls) {
1059
1060 Args.nullNotPermitted(orientation, "orientation");
1061 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
1062 categoryAxis.setCategoryMargin(0.0);
1063
1064 ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
1065
1066 AreaRenderer renderer = new AreaRenderer();
1067 if (tooltips) {
1068 renderer.setDefaultToolTipGenerator(
1069 new StandardCategoryToolTipGenerator());
1070 }
1071 if (urls) {
1072 renderer.setDefaultItemURLGenerator(
1073 new StandardCategoryURLGenerator());
1074 }
1075
1076 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
1077 renderer);
1078 plot.setOrientation(orientation);
1079 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1080 plot, legend);
1081 currentTheme.apply(chart);
1082 return chart;
1083
1084 }
1085
1086 /**
1087 * Creates a stacked area chart with default settings. The chart object
1088 * returned by this method uses a {@link CategoryPlot} instance as the
1089 * plot, with a {@link CategoryAxis} for the domain axis, a
1090 * {@link NumberAxis} as the range axis, and a {@link StackedAreaRenderer}
1091 * as the renderer.
1092 *
1093 * @param title the chart title ({@code null} permitted).
1094 * @param categoryAxisLabel the label for the category axis
1095 * ({@code null} permitted).
1096 * @param valueAxisLabel the label for the value axis ({@code null}
1097 * permitted).
1098 * @param dataset the dataset for the chart ({@code null} permitted).
1099 *
1100 * @return A stacked area chart.
1101 *
1102 * @since 1.0.16
1103 */
1104 public static JFreeChart createStackedAreaChart(String title,
1105 String categoryAxisLabel, String valueAxisLabel,
1106 CategoryDataset dataset) {
1107 return createStackedAreaChart(title, categoryAxisLabel, valueAxisLabel,
1108 dataset, PlotOrientation.VERTICAL, true, true, false);
1109 }
1110
1111 /**
1112 * Creates a stacked area chart with default settings. The chart object
1113 * returned by this method uses a {@link CategoryPlot} instance as the
1114 * plot, with a {@link CategoryAxis} for the domain axis, a
1115 * {@link NumberAxis} as the range axis, and a {@link StackedAreaRenderer}
1116 * as the renderer.
1117 *
1118 * @param title the chart title ({@code null} permitted).
1119 * @param categoryAxisLabel the label for the category axis
1120 * ({@code null} permitted).
1121 * @param valueAxisLabel the label for the value axis ({@code null}
1122 * permitted).
1123 * @param dataset the dataset for the chart ({@code null} permitted).
1124 * @param orientation the plot orientation (horizontal or vertical)
1125 * ({@code null} not permitted).
1126 * @param legend a flag specifying whether or not a legend is required.
1127 * @param tooltips configure chart to generate tool tips?
1128 * @param urls configure chart to generate URLs?
1129 *
1130 * @return A stacked area chart.
1131 */
1132 public static JFreeChart createStackedAreaChart(String title,
1133 String categoryAxisLabel, String valueAxisLabel,
1134 CategoryDataset dataset, PlotOrientation orientation,
1135 boolean legend, boolean tooltips, boolean urls) {
1136
1137 Args.nullNotPermitted(orientation, "orientation");
1138 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
1139 categoryAxis.setCategoryMargin(0.0);
1140 ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
1141
1142 StackedAreaRenderer renderer = new StackedAreaRenderer();
1143 if (tooltips) {
1144 renderer.setDefaultToolTipGenerator(
1145 new StandardCategoryToolTipGenerator());
1146 }
1147 if (urls) {
1148 renderer.setDefaultItemURLGenerator(
1149 new StandardCategoryURLGenerator());
1150 }
1151
1152 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
1153 renderer);
1154 plot.setOrientation(orientation);
1155 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1156 plot, legend);
1157 currentTheme.apply(chart);
1158 return chart;
1159
1160 }
1161
1162 /**
1163 * Creates a line chart with default settings. The chart object returned
1164 * by this method uses a {@link CategoryPlot} instance as the plot, with a
1165 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the
1166 * range axis, and a {@link LineAndShapeRenderer} as the renderer.
1167 *
1168 * @param title the chart title ({@code null} permitted).
1169 * @param categoryAxisLabel the label for the category axis
1170 * ({@code null} permitted).
1171 * @param valueAxisLabel the label for the value axis ({@code null}
1172 * permitted).
1173 * @param dataset the dataset for the chart ({@code null} permitted).
1174 *
1175 * @return A line chart.
1176 *
1177 * @since 1.0.16
1178 */
1179 public static JFreeChart createLineChart(String title,
1180 String categoryAxisLabel, String valueAxisLabel,
1181 CategoryDataset dataset) {
1182 return createLineChart(title, categoryAxisLabel, valueAxisLabel,
1183 dataset, PlotOrientation.VERTICAL, true, true, false);
1184 }
1185
1186 /**
1187 * Creates a line chart with default settings. The chart object returned
1188 * by this method uses a {@link CategoryPlot} instance as the plot, with a
1189 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the
1190 * range axis, and a {@link LineAndShapeRenderer} as the renderer.
1191 *
1192 * @param title the chart title ({@code null} permitted).
1193 * @param categoryAxisLabel the label for the category axis
1194 * ({@code null} permitted).
1195 * @param valueAxisLabel the label for the value axis ({@code null}
1196 * permitted).
1197 * @param dataset the dataset for the chart ({@code null} permitted).
1198 * @param orientation the chart orientation (horizontal or vertical)
1199 * ({@code null} not permitted).
1200 * @param legend a flag specifying whether or not a legend is required.
1201 * @param tooltips configure chart to generate tool tips?
1202 * @param urls configure chart to generate URLs?
1203 *
1204 * @return A line chart.
1205 */
1206 public static JFreeChart createLineChart(String title,
1207 String categoryAxisLabel, String valueAxisLabel,
1208 CategoryDataset dataset, PlotOrientation orientation,
1209 boolean legend, boolean tooltips, boolean urls) {
1210
1211 Args.nullNotPermitted(orientation, "orientation");
1212 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
1213 ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
1214
1215 LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false);
1216 if (tooltips) {
1217 renderer.setDefaultToolTipGenerator(
1218 new StandardCategoryToolTipGenerator());
1219 }
1220 if (urls) {
1221 renderer.setDefaultItemURLGenerator(
1222 new StandardCategoryURLGenerator());
1223 }
1224 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
1225 renderer);
1226 plot.setOrientation(orientation);
1227 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1228 plot, legend);
1229 currentTheme.apply(chart);
1230 return chart;
1231
1232 }
1233
1234 /**
1235 * Creates a Gantt chart using the supplied attributes plus default values
1236 * where required. The chart object returned by this method uses a
1237 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis}
1238 * for the domain axis, a {@link DateAxis} as the range axis, and a
1239 * {@link GanttRenderer} as the renderer.
1240 *
1241 * @param title the chart title ({@code null} permitted).
1242 * @param categoryAxisLabel the label for the category axis
1243 * ({@code null} permitted).
1244 * @param dateAxisLabel the label for the date axis
1245 * ({@code null} permitted).
1246 * @param dataset the dataset for the chart ({@code null} permitted).
1247 *
1248 * @return A Gantt chart.
1249 *
1250 * @since 1.0.16
1251 */
1252 public static JFreeChart createGanttChart(String title,
1253 String categoryAxisLabel, String dateAxisLabel,
1254 IntervalCategoryDataset dataset) {
1255 return createGanttChart(title, categoryAxisLabel, dateAxisLabel,
1256 dataset, true, true, false);
1257 }
1258
1259 /**
1260 * Creates a Gantt chart using the supplied attributes plus default values
1261 * where required. The chart object returned by this method uses a
1262 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis}
1263 * for the domain axis, a {@link DateAxis} as the range axis, and a
1264 * {@link GanttRenderer} as the renderer.
1265 *
1266 * @param title the chart title ({@code null} permitted).
1267 * @param categoryAxisLabel the label for the category axis
1268 * ({@code null} permitted).
1269 * @param dateAxisLabel the label for the date axis
1270 * ({@code null} permitted).
1271 * @param dataset the dataset for the chart ({@code null} permitted).
1272 * @param legend a flag specifying whether or not a legend is required.
1273 * @param tooltips configure chart to generate tool tips?
1274 * @param urls configure chart to generate URLs?
1275 *
1276 * @return A Gantt chart.
1277 */
1278 public static JFreeChart createGanttChart(String title,
1279 String categoryAxisLabel, String dateAxisLabel,
1280 IntervalCategoryDataset dataset, boolean legend, boolean tooltips,
1281 boolean urls) {
1282
1283 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
1284 DateAxis dateAxis = new DateAxis(dateAxisLabel);
1285
1286 CategoryItemRenderer renderer = new GanttRenderer();
1287 if (tooltips) {
1288 renderer.setDefaultToolTipGenerator(
1289 new IntervalCategoryToolTipGenerator(
1290 "{3} - {4}", DateFormat.getDateInstance()));
1291 }
1292 if (urls) {
1293 renderer.setDefaultItemURLGenerator(
1294 new StandardCategoryURLGenerator());
1295 }
1296
1297 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, dateAxis,
1298 renderer);
1299 plot.setOrientation(PlotOrientation.HORIZONTAL);
1300 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1301 plot, legend);
1302 currentTheme.apply(chart);
1303 return chart;
1304
1305 }
1306
1307 /**
1308 * Creates a waterfall chart. The chart object returned by this method
1309 * uses a {@link CategoryPlot} instance as the plot, with a
1310 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the
1311 * range axis, and a {@link WaterfallBarRenderer} as the renderer.
1312 *
1313 * @param title the chart title ({@code null} permitted).
1314 * @param categoryAxisLabel the label for the category axis
1315 * ({@code null} permitted).
1316 * @param valueAxisLabel the label for the value axis ({@code null}
1317 * permitted).
1318 * @param dataset the dataset for the chart ({@code null} permitted).
1319 * @param orientation the plot orientation (horizontal or vertical)
1320 * ({@code null} NOT permitted).
1321 * @param legend a flag specifying whether or not a legend is required.
1322 * @param tooltips configure chart to generate tool tips?
1323 * @param urls configure chart to generate URLs?
1324 *
1325 * @return A waterfall chart.
1326 */
1327 public static JFreeChart createWaterfallChart(String title,
1328 String categoryAxisLabel, String valueAxisLabel,
1329 CategoryDataset dataset, PlotOrientation orientation,
1330 boolean legend, boolean tooltips, boolean urls) {
1331
1332 Args.nullNotPermitted(orientation, "orientation");
1333 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
1334 categoryAxis.setCategoryMargin(0.0);
1335
1336 ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
1337
1338 WaterfallBarRenderer renderer = new WaterfallBarRenderer();
1339 if (orientation == PlotOrientation.HORIZONTAL) {
1340 ItemLabelPosition position = new ItemLabelPosition(
1341 ItemLabelAnchor.CENTER, TextAnchor.CENTER,
1342 TextAnchor.CENTER, Math.PI / 2.0);
1343 renderer.setDefaultPositiveItemLabelPosition(position);
1344 renderer.setDefaultNegativeItemLabelPosition(position);
1345 }
1346 else if (orientation == PlotOrientation.VERTICAL) {
1347 ItemLabelPosition position = new ItemLabelPosition(
1348 ItemLabelAnchor.CENTER, TextAnchor.CENTER,
1349 TextAnchor.CENTER, 0.0);
1350 renderer.setDefaultPositiveItemLabelPosition(position);
1351 renderer.setDefaultNegativeItemLabelPosition(position);
1352 }
1353 if (tooltips) {
1354 StandardCategoryToolTipGenerator generator
1355 = new StandardCategoryToolTipGenerator();
1356 renderer.setDefaultToolTipGenerator(generator);
1357 }
1358 if (urls) {
1359 renderer.setDefaultItemURLGenerator(
1360 new StandardCategoryURLGenerator());
1361 }
1362
1363 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
1364 renderer);
1365 plot.clearRangeMarkers();
1366 Marker baseline = new ValueMarker(0.0);
1367 baseline.setPaint(Color.BLACK);
1368 plot.addRangeMarker(baseline, Layer.FOREGROUND);
1369 plot.setOrientation(orientation);
1370 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1371 plot, legend);
1372 currentTheme.apply(chart);
1373 return chart;
1374
1375 }
1376
1377 /**
1378 * Creates a polar plot for the specified dataset (x-values interpreted as
1379 * angles in degrees). The chart object returned by this method uses a
1380 * {@link PolarPlot} instance as the plot, with a {@link NumberAxis} for
1381 * the radial axis.
1382 *
1383 * @param title the chart title ({@code null} permitted).
1384 * @param dataset the dataset ({@code null} permitted).
1385 * @param legend legend required?
1386 * @param tooltips tooltips required?
1387 * @param urls URLs required?
1388 *
1389 * @return A chart.
1390 */
1391 public static JFreeChart createPolarChart(String title, XYDataset dataset,
1392 boolean legend, boolean tooltips, boolean urls) {
1393
1394 PolarPlot plot = new PolarPlot();
1395 plot.setDataset(dataset);
1396 NumberAxis rangeAxis = new NumberAxis();
1397 rangeAxis.setAxisLineVisible(false);
1398 rangeAxis.setTickMarksVisible(false);
1399 rangeAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
1400 plot.setAxis(rangeAxis);
1401 plot.setRenderer(new DefaultPolarItemRenderer());
1402 JFreeChart chart = new JFreeChart(
1403 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
1404 currentTheme.apply(chart);
1405 return chart;
1406
1407 }
1408
1409 /**
1410 * Creates a scatter plot with default settings. The chart object
1411 * returned by this method uses an {@link XYPlot} instance as the plot,
1412 * with a {@link NumberAxis} for the domain axis, a {@link NumberAxis}
1413 * as the range axis, and an {@link XYLineAndShapeRenderer} as the
1414 * renderer.
1415 *
1416 * @param title the chart title ({@code null} permitted).
1417 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1418 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1419 * @param dataset the dataset for the chart ({@code null} permitted).
1420 *
1421 * @return A scatter plot.
1422 *
1423 * @since 1.0.16
1424 */
1425 public static JFreeChart createScatterPlot(String title, String xAxisLabel,
1426 String yAxisLabel, XYDataset dataset) {
1427 return createScatterPlot(title, xAxisLabel, yAxisLabel, dataset,
1428 PlotOrientation.VERTICAL, true, true, false);
1429 }
1430
1431 /**
1432 * Creates a scatter plot with default settings. The chart object
1433 * returned by this method uses an {@link XYPlot} instance as the plot,
1434 * with a {@link NumberAxis} for the domain axis, a {@link NumberAxis}
1435 * as the range axis, and an {@link XYLineAndShapeRenderer} as the
1436 * renderer.
1437 *
1438 * @param title the chart title ({@code null} permitted).
1439 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1440 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1441 * @param dataset the dataset for the chart ({@code null} permitted).
1442 * @param orientation the plot orientation (horizontal or vertical)
1443 * ({@code null} NOT permitted).
1444 * @param legend a flag specifying whether or not a legend is required.
1445 * @param tooltips configure chart to generate tool tips?
1446 * @param urls configure chart to generate URLs?
1447 *
1448 * @return A scatter plot.
1449 */
1450 public static JFreeChart createScatterPlot(String title, String xAxisLabel,
1451 String yAxisLabel, XYDataset dataset, PlotOrientation orientation,
1452 boolean legend, boolean tooltips, boolean urls) {
1453
1454 Args.nullNotPermitted(orientation, "orientation");
1455 NumberAxis xAxis = new NumberAxis(xAxisLabel);
1456 xAxis.setAutoRangeIncludesZero(false);
1457 NumberAxis yAxis = new NumberAxis(yAxisLabel);
1458 yAxis.setAutoRangeIncludesZero(false);
1459
1460 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
1461
1462 XYToolTipGenerator toolTipGenerator = null;
1463 if (tooltips) {
1464 toolTipGenerator = new StandardXYToolTipGenerator();
1465 }
1466
1467 XYURLGenerator urlGenerator = null;
1468 if (urls) {
1469 urlGenerator = new StandardXYURLGenerator();
1470 }
1471 XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
1472 renderer.setDefaultToolTipGenerator(toolTipGenerator);
1473 renderer.setURLGenerator(urlGenerator);
1474 plot.setRenderer(renderer);
1475 plot.setOrientation(orientation);
1476
1477 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1478 plot, legend);
1479 currentTheme.apply(chart);
1480 return chart;
1481
1482 }
1483
1484 /**
1485 * Creates and returns a default instance of an XY bar chart.
1486 * <P>
1487 * The chart object returned by this method uses an {@link XYPlot} instance
1488 * as the plot, with a {@link DateAxis} for the domain axis, a
1489 * {@link NumberAxis} as the range axis, and a {@link XYBarRenderer} as the
1490 * renderer.
1491 *
1492 * @param title the chart title ({@code null} permitted).
1493 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1494 * @param dateAxis make the domain axis display dates?
1495 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1496 * @param dataset the dataset for the chart ({@code null} permitted).
1497 *
1498 * @return An XY bar chart.
1499 *
1500 * @since 1.0.16
1501 */
1502 public static JFreeChart createXYBarChart(String title, String xAxisLabel,
1503 boolean dateAxis, String yAxisLabel, IntervalXYDataset dataset) {
1504 return createXYBarChart(title, xAxisLabel, dateAxis, yAxisLabel,
1505 dataset, PlotOrientation.VERTICAL, true, true, false);
1506 }
1507
1508 /**
1509 * Creates and returns a default instance of an XY bar chart.
1510 * <P>
1511 * The chart object returned by this method uses an {@link XYPlot} instance
1512 * as the plot, with a {@link DateAxis} for the domain axis, a
1513 * {@link NumberAxis} as the range axis, and a {@link XYBarRenderer} as the
1514 * renderer.
1515 *
1516 * @param title the chart title ({@code null} permitted).
1517 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1518 * @param dateAxis make the domain axis display dates?
1519 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1520 * @param dataset the dataset for the chart ({@code null} permitted).
1521 * @param orientation the orientation (horizontal or vertical)
1522 * ({@code null} NOT permitted).
1523 * @param legend a flag specifying whether or not a legend is required.
1524 * @param tooltips configure chart to generate tool tips?
1525 * @param urls configure chart to generate URLs?
1526 *
1527 * @return An XY bar chart.
1528 */
1529 public static JFreeChart createXYBarChart(String title, String xAxisLabel,
1530 boolean dateAxis, String yAxisLabel, IntervalXYDataset dataset,
1531 PlotOrientation orientation, boolean legend, boolean tooltips,
1532 boolean urls) {
1533
1534 Args.nullNotPermitted(orientation, "orientation");
1535 ValueAxis domainAxis;
1536 if (dateAxis) {
1537 domainAxis = new DateAxis(xAxisLabel);
1538 }
1539 else {
1540 NumberAxis axis = new NumberAxis(xAxisLabel);
1541 axis.setAutoRangeIncludesZero(false);
1542 domainAxis = axis;
1543 }
1544 ValueAxis valueAxis = new NumberAxis(yAxisLabel);
1545
1546 XYBarRenderer renderer = new XYBarRenderer();
1547 if (tooltips) {
1548 XYToolTipGenerator tt;
1549 if (dateAxis) {
1550 tt = StandardXYToolTipGenerator.getTimeSeriesInstance();
1551 }
1552 else {
1553 tt = new StandardXYToolTipGenerator();
1554 }
1555 renderer.setDefaultToolTipGenerator(tt);
1556 }
1557 if (urls) {
1558 renderer.setURLGenerator(new StandardXYURLGenerator());
1559 }
1560
1561 XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer);
1562 plot.setOrientation(orientation);
1563
1564 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1565 plot, legend);
1566 currentTheme.apply(chart);
1567 return chart;
1568
1569 }
1570
1571 /**
1572 * Creates an area chart using an {@link XYDataset}.
1573 * <P>
1574 * The chart object returned by this method uses an {@link XYPlot} instance
1575 * as the plot, with a {@link NumberAxis} for the domain axis, a
1576 * {@link NumberAxis} as the range axis, and a {@link XYAreaRenderer} as
1577 * the renderer.
1578 *
1579 * @param title the chart title ({@code null} permitted).
1580 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1581 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1582 * @param dataset the dataset for the chart ({@code null} permitted).
1583 *
1584 * @return An XY area chart.
1585 *
1586 * @since 1.0.16
1587 */
1588 public static JFreeChart createXYAreaChart(String title,String xAxisLabel,
1589 String yAxisLabel, XYDataset dataset) {
1590 return createXYAreaChart(title, xAxisLabel, yAxisLabel, dataset,
1591 PlotOrientation.VERTICAL, true, true, false);
1592 }
1593
1594 /**
1595 * Creates an area chart using an {@link XYDataset}.
1596 * <P>
1597 * The chart object returned by this method uses an {@link XYPlot} instance
1598 * as the plot, with a {@link NumberAxis} for the domain axis, a
1599 * {@link NumberAxis} as the range axis, and a {@link XYAreaRenderer} as
1600 * the renderer.
1601 *
1602 * @param title the chart title ({@code null} permitted).
1603 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1604 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1605 * @param dataset the dataset for the chart ({@code null} permitted).
1606 * @param orientation the plot orientation (horizontal or vertical)
1607 * ({@code null} NOT permitted).
1608 * @param legend a flag specifying whether or not a legend is required.
1609 * @param tooltips configure chart to generate tool tips?
1610 * @param urls configure chart to generate URLs?
1611 *
1612 * @return An XY area chart.
1613 */
1614 public static JFreeChart createXYAreaChart(String title, String xAxisLabel,
1615 String yAxisLabel, XYDataset dataset, PlotOrientation orientation,
1616 boolean legend, boolean tooltips, boolean urls) {
1617
1618 Args.nullNotPermitted(orientation, "orientation");
1619 NumberAxis xAxis = new NumberAxis(xAxisLabel);
1620 xAxis.setAutoRangeIncludesZero(false);
1621 NumberAxis yAxis = new NumberAxis(yAxisLabel);
1622 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
1623 plot.setOrientation(orientation);
1624 plot.setForegroundAlpha(0.5f);
1625
1626 XYToolTipGenerator tipGenerator = null;
1627 if (tooltips) {
1628 tipGenerator = new StandardXYToolTipGenerator();
1629 }
1630
1631 XYURLGenerator urlGenerator = null;
1632 if (urls) {
1633 urlGenerator = new StandardXYURLGenerator();
1634 }
1635
1636 plot.setRenderer(new XYAreaRenderer(XYAreaRenderer.AREA, tipGenerator,
1637 urlGenerator));
1638 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1639 plot, legend);
1640 currentTheme.apply(chart);
1641 return chart;
1642
1643 }
1644
1645 /**
1646 * Creates a stacked XY area plot. The chart object returned by this
1647 * method uses an {@link XYPlot} instance as the plot, with a
1648 * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the
1649 * range axis, and a {@link StackedXYAreaRenderer2} as the renderer.
1650 *
1651 * @param title the chart title ({@code null} permitted).
1652 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1653 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1654 * @param dataset the dataset for the chart ({@code null} permitted).
1655 *
1656 * @return A stacked XY area chart.
1657 *
1658 * @since 1.0.16
1659 */
1660 public static JFreeChart createStackedXYAreaChart(String title,
1661 String xAxisLabel, String yAxisLabel, TableXYDataset dataset) {
1662 return createStackedXYAreaChart(title, xAxisLabel, yAxisLabel,
1663 dataset, PlotOrientation.VERTICAL, true, true, false);
1664 }
1665
1666 /**
1667 * Creates a stacked XY area plot. The chart object returned by this
1668 * method uses an {@link XYPlot} instance as the plot, with a
1669 * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the
1670 * range axis, and a {@link StackedXYAreaRenderer2} as the renderer.
1671 *
1672 * @param title the chart title ({@code null} permitted).
1673 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1674 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1675 * @param dataset the dataset for the chart ({@code null} permitted).
1676 * @param orientation the plot orientation (horizontal or vertical)
1677 * ({@code null} NOT permitted).
1678 * @param legend a flag specifying whether or not a legend is required.
1679 * @param tooltips configure chart to generate tool tips?
1680 * @param urls configure chart to generate URLs?
1681 *
1682 * @return A stacked XY area chart.
1683 */
1684 public static JFreeChart createStackedXYAreaChart(String title,
1685 String xAxisLabel, String yAxisLabel, TableXYDataset dataset,
1686 PlotOrientation orientation, boolean legend, boolean tooltips,
1687 boolean urls) {
1688
1689 Args.nullNotPermitted(orientation, "orientation");
1690 NumberAxis xAxis = new NumberAxis(xAxisLabel);
1691 xAxis.setAutoRangeIncludesZero(false);
1692 xAxis.setLowerMargin(0.0);
1693 xAxis.setUpperMargin(0.0);
1694 NumberAxis yAxis = new NumberAxis(yAxisLabel);
1695 XYToolTipGenerator toolTipGenerator = null;
1696 if (tooltips) {
1697 toolTipGenerator = new StandardXYToolTipGenerator();
1698 }
1699
1700 XYURLGenerator urlGenerator = null;
1701 if (urls) {
1702 urlGenerator = new StandardXYURLGenerator();
1703 }
1704 StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(
1705 toolTipGenerator, urlGenerator);
1706 renderer.setOutline(true);
1707 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
1708 plot.setOrientation(orientation);
1709
1710 plot.setRangeAxis(yAxis); // forces recalculation of the axis range
1711
1712 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1713 plot, legend);
1714 currentTheme.apply(chart);
1715 return chart;
1716
1717 }
1718
1719 /**
1720 * Creates a line chart (based on an {@link XYDataset}) with default
1721 * settings.
1722 *
1723 * @param title the chart title ({@code null} permitted).
1724 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1725 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1726 * @param dataset the dataset for the chart ({@code null} permitted).
1727 *
1728 * @return The chart.
1729 */
1730 public static JFreeChart createXYLineChart(String title,
1731 String xAxisLabel, String yAxisLabel, XYDataset dataset) {
1732 return createXYLineChart(title, xAxisLabel, yAxisLabel, dataset,
1733 PlotOrientation.VERTICAL, true, true, false);
1734 }
1735
1736 /**
1737 * Creates a line chart (based on an {@link XYDataset}) with default
1738 * settings.
1739 *
1740 * @param title the chart title ({@code null} permitted).
1741 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1742 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1743 * @param dataset the dataset for the chart ({@code null} permitted).
1744 * @param orientation the plot orientation (horizontal or vertical)
1745 * ({@code null} NOT permitted).
1746 * @param legend a flag specifying whether or not a legend is required.
1747 * @param tooltips configure chart to generate tool tips?
1748 * @param urls configure chart to generate URLs?
1749 *
1750 * @return The chart.
1751 */
1752 public static JFreeChart createXYLineChart(String title, String xAxisLabel,
1753 String yAxisLabel, XYDataset dataset, PlotOrientation orientation,
1754 boolean legend, boolean tooltips, boolean urls) {
1755
1756 Args.nullNotPermitted(orientation, "orientation");
1757 NumberAxis xAxis = new NumberAxis(xAxisLabel);
1758 xAxis.setAutoRangeIncludesZero(false);
1759 NumberAxis yAxis = new NumberAxis(yAxisLabel);
1760 XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
1761 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
1762 plot.setOrientation(orientation);
1763 if (tooltips) {
1764 renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator());
1765 }
1766 if (urls) {
1767 renderer.setURLGenerator(new StandardXYURLGenerator());
1768 }
1769
1770 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1771 plot, legend);
1772 currentTheme.apply(chart);
1773 return chart;
1774
1775 }
1776
1777 /**
1778 * Creates a stepped XY plot with default settings.
1779 *
1780 * @param title the chart title ({@code null} permitted).
1781 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1782 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1783 * @param dataset the dataset for the chart ({@code null} permitted).
1784 *
1785 * @return A chart.
1786 *
1787 * @since 1.0.16
1788 */
1789 public static JFreeChart createXYStepChart(String title, String xAxisLabel,
1790 String yAxisLabel, XYDataset dataset) {
1791 return createXYStepChart(title, xAxisLabel, yAxisLabel, dataset,
1792 PlotOrientation.VERTICAL, true, true, false);
1793 }
1794
1795 /**
1796 * Creates a stepped XY plot with default settings.
1797 *
1798 * @param title the chart title ({@code null} permitted).
1799 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1800 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1801 * @param dataset the dataset for the chart ({@code null} permitted).
1802 * @param orientation the plot orientation (horizontal or vertical)
1803 * ({@code null} NOT permitted).
1804 * @param legend a flag specifying whether or not a legend is required.
1805 * @param tooltips configure chart to generate tool tips?
1806 * @param urls configure chart to generate URLs?
1807 *
1808 * @return A chart.
1809 */
1810 public static JFreeChart createXYStepChart(String title, String xAxisLabel,
1811 String yAxisLabel, XYDataset dataset, PlotOrientation orientation,
1812 boolean legend, boolean tooltips, boolean urls) {
1813
1814 Args.nullNotPermitted(orientation, "orientation");
1815 DateAxis xAxis = new DateAxis(xAxisLabel);
1816 NumberAxis yAxis = new NumberAxis(yAxisLabel);
1817 yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
1818
1819 XYToolTipGenerator toolTipGenerator = null;
1820 if (tooltips) {
1821 toolTipGenerator = new StandardXYToolTipGenerator();
1822 }
1823
1824 XYURLGenerator urlGenerator = null;
1825 if (urls) {
1826 urlGenerator = new StandardXYURLGenerator();
1827 }
1828 XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator,
1829 urlGenerator);
1830
1831 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
1832 plot.setRenderer(renderer);
1833 plot.setOrientation(orientation);
1834 plot.setDomainCrosshairVisible(false);
1835 plot.setRangeCrosshairVisible(false);
1836 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1837 plot, legend);
1838 currentTheme.apply(chart);
1839 return chart;
1840
1841 }
1842
1843 /**
1844 * Creates a filled stepped XY plot with default settings.
1845 *
1846 * @param title the chart title ({@code null} permitted).
1847 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1848 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1849 * @param dataset the dataset for the chart ({@code null} permitted).
1850 *
1851 * @return A chart.
1852 *
1853 * @since 1.0.16
1854 */
1855 public static JFreeChart createXYStepAreaChart(String title,
1856 String xAxisLabel, String yAxisLabel, XYDataset dataset) {
1857 return createXYStepAreaChart(title, xAxisLabel, yAxisLabel, dataset,
1858 PlotOrientation.VERTICAL, true, true, false);
1859 }
1860
1861 /**
1862 * Creates a filled stepped XY plot with default settings.
1863 *
1864 * @param title the chart title ({@code null} permitted).
1865 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
1866 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
1867 * @param dataset the dataset for the chart ({@code null} permitted).
1868 * @param orientation the plot orientation (horizontal or vertical)
1869 * ({@code null} NOT permitted).
1870 * @param legend a flag specifying whether or not a legend is required.
1871 * @param tooltips configure chart to generate tool tips?
1872 * @param urls configure chart to generate URLs?
1873 *
1874 * @return A chart.
1875 */
1876 public static JFreeChart createXYStepAreaChart(String title,
1877 String xAxisLabel, String yAxisLabel, XYDataset dataset,
1878 PlotOrientation orientation, boolean legend, boolean tooltips,
1879 boolean urls) {
1880
1881 Args.nullNotPermitted(orientation, "orientation");
1882 NumberAxis xAxis = new NumberAxis(xAxisLabel);
1883 xAxis.setAutoRangeIncludesZero(false);
1884 NumberAxis yAxis = new NumberAxis(yAxisLabel);
1885
1886 XYToolTipGenerator toolTipGenerator = null;
1887 if (tooltips) {
1888 toolTipGenerator = new StandardXYToolTipGenerator();
1889 }
1890
1891 XYURLGenerator urlGenerator = null;
1892 if (urls) {
1893 urlGenerator = new StandardXYURLGenerator();
1894 }
1895 XYItemRenderer renderer = new XYStepAreaRenderer(
1896 XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator,
1897 urlGenerator);
1898
1899 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
1900 plot.setRenderer(renderer);
1901 plot.setOrientation(orientation);
1902 plot.setDomainCrosshairVisible(false);
1903 plot.setRangeCrosshairVisible(false);
1904 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1905 plot, legend);
1906 currentTheme.apply(chart);
1907 return chart;
1908 }
1909
1910 /**
1911 * Creates and returns a time series chart. A time series chart is an
1912 * {@link XYPlot} with a {@link DateAxis} for the x-axis and a
1913 * {@link NumberAxis} for the y-axis. The default renderer is an
1914 * {@link XYLineAndShapeRenderer}.
1915 * <P>
1916 * A convenient dataset to use with this chart is a
1917 * {@link org.jfree.data.time.TimeSeriesCollection}.
1918 *
1919 * @param title the chart title ({@code null} permitted).
1920 * @param timeAxisLabel a label for the time axis ({@code null}
1921 * permitted).
1922 * @param valueAxisLabel a label for the value axis ({@code null}
1923 * permitted).
1924 * @param dataset the dataset for the chart ({@code null} permitted).
1925 *
1926 * @return A time series chart.
1927 *
1928 * @since 1.0.16
1929 */
1930 public static JFreeChart createTimeSeriesChart(String title,
1931 String timeAxisLabel, String valueAxisLabel, XYDataset dataset) {
1932 return createTimeSeriesChart(title, timeAxisLabel, valueAxisLabel,
1933 dataset, true, true, false);
1934 }
1935
1936 /**
1937 * Creates and returns a time series chart. A time series chart is an
1938 * {@link XYPlot} with a {@link DateAxis} for the x-axis and a
1939 * {@link NumberAxis} for the y-axis. The default renderer is an
1940 * {@link XYLineAndShapeRenderer}.
1941 * <P>
1942 * A convenient dataset to use with this chart is a
1943 * {@link org.jfree.data.time.TimeSeriesCollection}.
1944 *
1945 * @param title the chart title ({@code null} permitted).
1946 * @param timeAxisLabel a label for the time axis ({@code null}
1947 * permitted).
1948 * @param valueAxisLabel a label for the value axis ({@code null}
1949 * permitted).
1950 * @param dataset the dataset for the chart ({@code null} permitted).
1951 * @param legend a flag specifying whether or not a legend is required.
1952 * @param tooltips configure chart to generate tool tips?
1953 * @param urls configure chart to generate URLs?
1954 *
1955 * @return A time series chart.
1956 */
1957 public static JFreeChart createTimeSeriesChart(String title,
1958 String timeAxisLabel, String valueAxisLabel, XYDataset dataset,
1959 boolean legend, boolean tooltips, boolean urls) {
1960
1961 ValueAxis timeAxis = new DateAxis(timeAxisLabel);
1962 timeAxis.setLowerMargin(0.02); // reduce the default margins
1963 timeAxis.setUpperMargin(0.02);
1964 NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
1965 valueAxis.setAutoRangeIncludesZero(false); // override default
1966 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
1967
1968 XYToolTipGenerator toolTipGenerator = null;
1969 if (tooltips) {
1970 toolTipGenerator
1971 = StandardXYToolTipGenerator.getTimeSeriesInstance();
1972 }
1973
1974 XYURLGenerator urlGenerator = null;
1975 if (urls) {
1976 urlGenerator = new StandardXYURLGenerator();
1977 }
1978
1979 XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true,
1980 false);
1981 renderer.setDefaultToolTipGenerator(toolTipGenerator);
1982 renderer.setURLGenerator(urlGenerator);
1983 plot.setRenderer(renderer);
1984
1985 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1986 plot, legend);
1987 currentTheme.apply(chart);
1988 return chart;
1989
1990 }
1991
1992 /**
1993 * Creates and returns a default instance of a candlesticks chart.
1994 *
1995 * @param title the chart title ({@code null} permitted).
1996 * @param timeAxisLabel a label for the time axis ({@code null}
1997 * permitted).
1998 * @param valueAxisLabel a label for the value axis ({@code null}
1999 * permitted).
2000 * @param dataset the dataset for the chart ({@code null} permitted).
2001 * @param legend a flag specifying whether or not a legend is required.
2002 *
2003 * @return A candlestick chart.
2004 */
2005 public static JFreeChart createCandlestickChart(String title,
2006 String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
2007 boolean legend) {
2008
2009 ValueAxis timeAxis = new DateAxis(timeAxisLabel);
2010 NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
2011 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
2012 plot.setRenderer(new CandlestickRenderer());
2013 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
2014 plot, legend);
2015 currentTheme.apply(chart);
2016 return chart;
2017
2018 }
2019
2020 /**
2021 * Creates and returns a default instance of a high-low-open-close chart.
2022 *
2023 * @param title the chart title ({@code null} permitted).
2024 * @param timeAxisLabel a label for the time axis ({@code null}
2025 * permitted).
2026 * @param valueAxisLabel a label for the value axis ({@code null}
2027 * permitted).
2028 * @param dataset the dataset for the chart ({@code null} permitted).
2029 * @param legend a flag specifying whether or not a legend is required.
2030 *
2031 * @return A high-low-open-close chart.
2032 */
2033 public static JFreeChart createHighLowChart(String title,
2034 String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
2035 boolean legend) {
2036
2037 ValueAxis timeAxis = new DateAxis(timeAxisLabel);
2038 NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
2039 HighLowRenderer renderer = new HighLowRenderer();
2040 renderer.setDefaultToolTipGenerator(new HighLowItemLabelGenerator());
2041 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
2042 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
2043 plot, legend);
2044 currentTheme.apply(chart);
2045 return chart;
2046
2047 }
2048
2049 /**
2050 * Creates a bubble chart with default settings. The chart is composed of
2051 * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis,
2052 * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer}
2053 * to draw the data items.
2054 *
2055 * @param title the chart title ({@code null} permitted).
2056 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
2057 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
2058 * @param dataset the dataset for the chart ({@code null} permitted).
2059 *
2060 * @return A bubble chart.
2061 *
2062 * @since 1.0.16
2063 */
2064 public static JFreeChart createBubbleChart(String title, String xAxisLabel,
2065 String yAxisLabel, XYZDataset dataset) {
2066 return createBubbleChart(title, xAxisLabel, yAxisLabel, dataset,
2067 PlotOrientation.VERTICAL, true, true, false);
2068 }
2069
2070 /**
2071 * Creates a bubble chart with default settings. The chart is composed of
2072 * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis,
2073 * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer}
2074 * to draw the data items.
2075 *
2076 * @param title the chart title ({@code null} permitted).
2077 * @param xAxisLabel a label for the X-axis ({@code null} permitted).
2078 * @param yAxisLabel a label for the Y-axis ({@code null} permitted).
2079 * @param dataset the dataset for the chart ({@code null} permitted).
2080 * @param orientation the orientation (horizontal or vertical)
2081 * ({@code null} NOT permitted).
2082 * @param legend a flag specifying whether or not a legend is required.
2083 * @param tooltips configure chart to generate tool tips?
2084 * @param urls configure chart to generate URLs?
2085 *
2086 * @return A bubble chart.
2087 */
2088 public static JFreeChart createBubbleChart(String title, String xAxisLabel,
2089 String yAxisLabel, XYZDataset dataset, PlotOrientation orientation,
2090 boolean legend, boolean tooltips, boolean urls) {
2091
2092 Args.nullNotPermitted(orientation, "orientation");
2093 NumberAxis xAxis = new NumberAxis(xAxisLabel);
2094 xAxis.setAutoRangeIncludesZero(false);
2095 NumberAxis yAxis = new NumberAxis(yAxisLabel);
2096 yAxis.setAutoRangeIncludesZero(false);
2097
2098 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
2099
2100 XYItemRenderer renderer = new XYBubbleRenderer(
2101 XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
2102 if (tooltips) {
2103 renderer.setDefaultToolTipGenerator(new StandardXYZToolTipGenerator());
2104 }
2105 if (urls) {
2106 renderer.setURLGenerator(new StandardXYZURLGenerator());
2107 }
2108 plot.setRenderer(renderer);
2109 plot.setOrientation(orientation);
2110
2111 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
2112 plot, legend);
2113 currentTheme.apply(chart);
2114 return chart;
2115
2116 }
2117
2118 /**
2119 * Creates a histogram chart. This chart is constructed with an
2120 * {@link XYPlot} using an {@link XYBarRenderer}. The domain and range
2121 * axes are {@link NumberAxis} instances.
2122 *
2123 * @param title the chart title ({@code null} permitted).
2124 * @param xAxisLabel the x axis label ({@code null} permitted).
2125 * @param yAxisLabel the y axis label ({@code null} permitted).
2126 * @param dataset the dataset ({@code null} permitted).
2127 * @return A chart.
2128 *
2129 * @since 1.0.20
2130 */
2131 public static JFreeChart createHistogram(String title,
2132 String xAxisLabel, String yAxisLabel, IntervalXYDataset dataset) {
2133 return createHistogram(title, xAxisLabel, yAxisLabel, dataset,
2134 PlotOrientation.VERTICAL, true, true, false);
2135 }
2136
2137 /**
2138 * Creates a histogram chart. This chart is constructed with an
2139 * {@link XYPlot} using an {@link XYBarRenderer}. The domain and range
2140 * axes are {@link NumberAxis} instances.
2141 *
2142 * @param title the chart title ({@code null} permitted).
2143 * @param xAxisLabel the x axis label ({@code null} permitted).
2144 * @param yAxisLabel the y axis label ({@code null} permitted).
2145 * @param dataset the dataset ({@code null} permitted).
2146 * @param orientation the orientation (horizontal or vertical)
2147 * ({@code null} NOT permitted).
2148 * @param legend create a legend?
2149 * @param tooltips display tooltips?
2150 * @param urls generate URLs?
2151 *
2152 * @return The chart.
2153 */
2154 public static JFreeChart createHistogram(String title,
2155 String xAxisLabel, String yAxisLabel, IntervalXYDataset dataset,
2156 PlotOrientation orientation, boolean legend, boolean tooltips,
2157 boolean urls) {
2158
2159 Args.nullNotPermitted(orientation, "orientation");
2160 NumberAxis xAxis = new NumberAxis(xAxisLabel);
2161 xAxis.setAutoRangeIncludesZero(false);
2162 ValueAxis yAxis = new NumberAxis(yAxisLabel);
2163
2164 XYItemRenderer renderer = new XYBarRenderer();
2165 if (tooltips) {
2166 renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator());
2167 }
2168 if (urls) {
2169 renderer.setURLGenerator(new StandardXYURLGenerator());
2170 }
2171
2172 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
2173 plot.setOrientation(orientation);
2174 plot.setDomainZeroBaselineVisible(true);
2175 plot.setRangeZeroBaselineVisible(true);
2176 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
2177 plot, legend);
2178 currentTheme.apply(chart);
2179 return chart;
2180
2181 }
2182
2183 /**
2184 * Creates and returns a default instance of a box and whisker chart
2185 * based on data from a {@link BoxAndWhiskerCategoryDataset}.
2186 *
2187 * @param title the chart title ({@code null} permitted).
2188 * @param categoryAxisLabel a label for the category axis
2189 * ({@code null} permitted).
2190 * @param valueAxisLabel a label for the value axis ({@code null}
2191 * permitted).
2192 * @param dataset the dataset for the chart ({@code null} permitted).
2193 * @param legend a flag specifying whether or not a legend is required.
2194 *
2195 * @return A box and whisker chart.
2196 *
2197 * @since 1.0.4
2198 */
2199 public static JFreeChart createBoxAndWhiskerChart(String title,
2200 String categoryAxisLabel, String valueAxisLabel,
2201 BoxAndWhiskerCategoryDataset dataset, boolean legend) {
2202
2203 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
2204 NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
2205 valueAxis.setAutoRangeIncludesZero(false);
2206
2207 BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
2208 renderer.setDefaultToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
2209
2210 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
2211 renderer);
2212 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
2213 plot, legend);
2214 currentTheme.apply(chart);
2215 return chart;
2216 }
2217
2218 /**
2219 * Creates and returns a default instance of a box and whisker chart.
2220 *
2221 * @param title the chart title ({@code null} permitted).
2222 * @param timeAxisLabel a label for the time axis ({@code null}
2223 * permitted).
2224 * @param valueAxisLabel a label for the value axis ({@code null}
2225 * permitted).
2226 * @param dataset the dataset for the chart ({@code null} permitted).
2227 * @param legend a flag specifying whether or not a legend is required.
2228 *
2229 * @return A box and whisker chart.
2230 */
2231 public static JFreeChart createBoxAndWhiskerChart(String title,
2232 String timeAxisLabel, String valueAxisLabel,
2233 BoxAndWhiskerXYDataset dataset, boolean legend) {
2234
2235 ValueAxis timeAxis = new DateAxis(timeAxisLabel);
2236 NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
2237 valueAxis.setAutoRangeIncludesZero(false);
2238 XYBoxAndWhiskerRenderer renderer = new XYBoxAndWhiskerRenderer(10.0);
2239 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
2240 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
2241 plot, legend);
2242 currentTheme.apply(chart);
2243 return chart;
2244
2245 }
2246
2247 /**
2248 * Creates a wind plot with default settings.
2249 *
2250 * @param title the chart title ({@code null} permitted).
2251 * @param xAxisLabel a label for the x-axis ({@code null} permitted).
2252 * @param yAxisLabel a label for the y-axis ({@code null} permitted).
2253 * @param dataset the dataset for the chart ({@code null} permitted).
2254 * @param legend a flag that controls whether or not a legend is created.
2255 * @param tooltips configure chart to generate tool tips?
2256 * @param urls configure chart to generate URLs?
2257 *
2258 * @return A wind plot.
2259 *
2260 */
2261 public static JFreeChart createWindPlot(String title, String xAxisLabel,
2262 String yAxisLabel, WindDataset dataset, boolean legend,
2263 boolean tooltips, boolean urls) {
2264
2265 ValueAxis xAxis = new DateAxis(xAxisLabel);
2266 ValueAxis yAxis = new NumberAxis(yAxisLabel);
2267 yAxis.setRange(-12.0, 12.0);
2268
2269 WindItemRenderer renderer = new WindItemRenderer();
2270 if (tooltips) {
2271 renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator());
2272 }
2273 if (urls) {
2274 renderer.setURLGenerator(new StandardXYURLGenerator());
2275 }
2276 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
2277 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
2278 plot, legend);
2279 currentTheme.apply(chart);
2280 return chart;
2281
2282 }
2283
2284 /**
2285 * Creates a wafer map chart.
2286 *
2287 * @param title the chart title ({@code null} permitted).
2288 * @param dataset the dataset ({@code null} permitted).
2289 * @param orientation the plot orientation (horizontal or vertical)
2290 * ({@code null} NOT permitted.
2291 * @param legend display a legend?
2292 * @param tooltips generate tooltips?
2293 * @param urls generate URLs?
2294 *
2295 * @return A wafer map chart.
2296 */
2297 public static JFreeChart createWaferMapChart(String title,
2298 WaferMapDataset dataset, PlotOrientation orientation,
2299 boolean legend, boolean tooltips, boolean urls) {
2300
2301 Args.nullNotPermitted(orientation, "orientation");
2302 WaferMapPlot plot = new WaferMapPlot(dataset);
2303 WaferMapRenderer renderer = new WaferMapRenderer();
2304 plot.setRenderer(renderer);
2305
2306 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
2307 plot, legend);
2308 currentTheme.apply(chart);
2309 return chart;
2310 }
2311
2312}