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