001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2022, by David Gilbert 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-2022, by David Gilbert and Contributors. 031 * 032 * Original Author: David Gilbert; 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 */ 044 045package org.jfree.chart; 046 047import java.awt.Color; 048import java.awt.Font; 049import java.text.DateFormat; 050import java.text.NumberFormat; 051import java.util.Iterator; 052import java.util.List; 053import java.util.Locale; 054 055import org.jfree.chart.axis.CategoryAxis; 056import org.jfree.chart.axis.DateAxis; 057import org.jfree.chart.axis.NumberAxis; 058import org.jfree.chart.axis.ValueAxis; 059import org.jfree.chart.labels.BoxAndWhiskerToolTipGenerator; 060import org.jfree.chart.labels.HighLowItemLabelGenerator; 061import org.jfree.chart.labels.IntervalCategoryToolTipGenerator; 062import org.jfree.chart.labels.ItemLabelAnchor; 063import org.jfree.chart.labels.ItemLabelPosition; 064import org.jfree.chart.labels.PieToolTipGenerator; 065import org.jfree.chart.labels.StandardCategoryToolTipGenerator; 066import org.jfree.chart.labels.StandardPieSectionLabelGenerator; 067import org.jfree.chart.labels.StandardPieToolTipGenerator; 068import org.jfree.chart.labels.StandardXYToolTipGenerator; 069import org.jfree.chart.labels.StandardXYZToolTipGenerator; 070import org.jfree.chart.labels.XYToolTipGenerator; 071import org.jfree.chart.plot.CategoryPlot; 072import org.jfree.chart.plot.Marker; 073import org.jfree.chart.plot.pie.MultiplePiePlot; 074import org.jfree.chart.plot.pie.PiePlot; 075import org.jfree.chart.plot.PlotOrientation; 076import org.jfree.chart.plot.PolarPlot; 077import org.jfree.chart.plot.RingPlot; 078import org.jfree.chart.plot.ValueMarker; 079import org.jfree.chart.plot.WaferMapPlot; 080import org.jfree.chart.plot.XYPlot; 081import org.jfree.chart.renderer.DefaultPolarItemRenderer; 082import org.jfree.chart.renderer.WaferMapRenderer; 083import org.jfree.chart.renderer.category.AreaRenderer; 084import org.jfree.chart.renderer.category.BarRenderer; 085import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer; 086import org.jfree.chart.renderer.category.CategoryItemRenderer; 087import org.jfree.chart.renderer.category.GanttRenderer; 088import org.jfree.chart.renderer.category.GradientBarPainter; 089import org.jfree.chart.renderer.category.LineAndShapeRenderer; 090import org.jfree.chart.renderer.category.StackedAreaRenderer; 091import org.jfree.chart.renderer.category.StackedBarRenderer; 092import org.jfree.chart.renderer.category.StandardBarPainter; 093import org.jfree.chart.renderer.category.WaterfallBarRenderer; 094import org.jfree.chart.renderer.xy.CandlestickRenderer; 095import org.jfree.chart.renderer.xy.GradientXYBarPainter; 096import org.jfree.chart.renderer.xy.HighLowRenderer; 097import org.jfree.chart.renderer.xy.StackedXYAreaRenderer2; 098import org.jfree.chart.renderer.xy.StandardXYBarPainter; 099import org.jfree.chart.renderer.xy.WindItemRenderer; 100import org.jfree.chart.renderer.xy.XYAreaRenderer; 101import org.jfree.chart.renderer.xy.XYBarRenderer; 102import org.jfree.chart.renderer.xy.XYBoxAndWhiskerRenderer; 103import org.jfree.chart.renderer.xy.XYBubbleRenderer; 104import org.jfree.chart.renderer.xy.XYItemRenderer; 105import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; 106import org.jfree.chart.renderer.xy.XYStepAreaRenderer; 107import org.jfree.chart.renderer.xy.XYStepRenderer; 108import org.jfree.chart.title.TextTitle; 109import org.jfree.chart.api.Layer; 110import org.jfree.chart.api.RectangleInsets; 111import org.jfree.chart.text.TextAnchor; 112import org.jfree.chart.urls.PieURLGenerator; 113import org.jfree.chart.urls.StandardCategoryURLGenerator; 114import org.jfree.chart.urls.StandardPieURLGenerator; 115import org.jfree.chart.urls.StandardXYURLGenerator; 116import org.jfree.chart.urls.StandardXYZURLGenerator; 117import org.jfree.chart.urls.XYURLGenerator; 118import org.jfree.chart.internal.Args; 119import org.jfree.chart.api.TableOrder; 120import org.jfree.data.category.CategoryDataset; 121import org.jfree.data.category.IntervalCategoryDataset; 122import org.jfree.data.general.DefaultPieDataset; 123import org.jfree.data.general.PieDataset; 124import org.jfree.data.general.WaferMapDataset; 125import org.jfree.data.statistics.BoxAndWhiskerCategoryDataset; 126import org.jfree.data.statistics.BoxAndWhiskerXYDataset; 127import org.jfree.data.xy.IntervalXYDataset; 128import org.jfree.data.xy.OHLCDataset; 129import org.jfree.data.xy.TableXYDataset; 130import org.jfree.data.xy.WindDataset; 131import org.jfree.data.xy.XYDataset; 132import org.jfree.data.xy.XYZDataset; 133 134/** 135 * A collection of utility methods for creating some standard charts with 136 * JFreeChart. 137 */ 138public abstract class ChartFactory { 139 140 /** The chart theme. */ 141 private static ChartTheme currentTheme = new StandardChartTheme("JFree"); 142 143 /** 144 * Returns the current chart theme used by the factory. 145 * 146 * @return The chart theme. 147 * 148 * @see #setChartTheme(ChartTheme) 149 * @see ChartUtils#applyCurrentTheme(JFreeChart) 150 */ 151 public static ChartTheme getChartTheme() { 152 return currentTheme; 153 } 154 155 /** 156 * Sets the current chart theme. This will be applied to all new charts 157 * created via methods in this class. 158 * 159 * @param theme the theme ({@code null} not permitted). 160 * 161 * @see #getChartTheme() 162 * @see ChartUtils#applyCurrentTheme(JFreeChart) 163 */ 164 public static void setChartTheme(ChartTheme theme) { 165 Args.nullNotPermitted(theme, "theme"); 166 currentTheme = theme; 167 168 // here we do a check to see if the user is installing the "Legacy" 169 // theme, and reset the bar painters in that case... 170 if (theme instanceof StandardChartTheme) { 171 StandardChartTheme sct = (StandardChartTheme) theme; 172 if (sct.getName().equals("Legacy")) { 173 BarRenderer.setDefaultBarPainter(new StandardBarPainter()); 174 XYBarRenderer.setDefaultBarPainter(new StandardXYBarPainter()); 175 } 176 else { 177 BarRenderer.setDefaultBarPainter(new GradientBarPainter()); 178 XYBarRenderer.setDefaultBarPainter(new GradientXYBarPainter()); 179 } 180 } 181 } 182 183 /** 184 * Creates a pie chart with default settings. 185 * <P> 186 * The chart object returned by this method uses a {@link PiePlot} instance 187 * as the plot. 188 * 189 * @param title the chart title ({@code null} permitted). 190 * @param dataset the dataset for the chart ({@code null} permitted). 191 * @param legend a flag specifying whether or not a legend is required. 192 * @param tooltips configure chart to generate tool tips? 193 * @param locale the locale ({@code null} not permitted). 194 * 195 * @return A pie chart. 196 */ 197 public static JFreeChart createPieChart(String title, PieDataset dataset, 198 boolean legend, boolean tooltips, Locale locale) { 199 200 PiePlot plot = new PiePlot(dataset); 201 plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); 202 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); 203 if (tooltips) { 204 plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); 205 } 206 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 207 plot, legend); 208 currentTheme.apply(chart); 209 return chart; 210 211 } 212 213 /** 214 * Creates a pie chart with default settings. 215 * <P> 216 * The chart object returned by this method uses a {@link PiePlot} instance 217 * as the plot. 218 * 219 * @param title the chart title ({@code null} permitted). 220 * @param dataset the dataset for the chart ({@code null} permitted). 221 * 222 * @return A pie chart. 223 */ 224 public static JFreeChart createPieChart(String title, PieDataset dataset) { 225 return createPieChart(title, dataset, true, true, false); 226 } 227 228 /** 229 * Creates a pie chart with default settings. 230 * <P> 231 * The chart object returned by this method uses a {@link PiePlot} instance 232 * as the plot. 233 * 234 * @param title the chart title ({@code null} permitted). 235 * @param dataset the dataset for the chart ({@code null} permitted). 236 * @param legend a flag specifying whether or not a legend is required. 237 * @param tooltips configure chart to generate tool tips? 238 * @param urls configure chart to generate URLs? 239 * 240 * @return A pie chart. 241 */ 242 public static JFreeChart createPieChart(String title, PieDataset dataset, 243 boolean legend, boolean tooltips, boolean urls) { 244 245 PiePlot plot = new PiePlot(dataset); 246 plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); 247 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); 248 if (tooltips) { 249 plot.setToolTipGenerator(new StandardPieToolTipGenerator()); 250 } 251 if (urls) { 252 plot.setURLGenerator(new StandardPieURLGenerator()); 253 } 254 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 255 plot, legend); 256 currentTheme.apply(chart); 257 return chart; 258 } 259 260 /** 261 * Creates a pie chart with default settings that compares 2 datasets. 262 * The colour of each section will be determined by the move from the value 263 * for the same key in {@code previousDataset}. ie if value1 > 264 * value2 then the section will be in green (unless 265 * {@code greenForIncrease} is {@code false}, in which case it 266 * would be {@code red}). Each section can have a shade of red or 267 * green as the difference can be tailored between 0% (black) and 268 * percentDiffForMaxScale% (bright red/green). 269 * <p> 270 * For instance if {@code percentDiffForMaxScale} is 10 (10%), a 271 * difference of 5% will have a half shade of red/green, a difference of 272 * 10% or more will have a maximum shade/brightness of red/green. 273 * <P> 274 * The chart object returned by this method uses a {@link PiePlot} instance 275 * as the plot. 276 * <p> 277 * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit 278 * Xhenseval</a>. 279 * 280 * @param title the chart title ({@code null} permitted). 281 * @param dataset the dataset for the chart ({@code null} permitted). 282 * @param previousDataset the dataset for the last run, this will be used 283 * to compare each key in the dataset 284 * @param percentDiffForMaxScale scale goes from bright red/green to black, 285 * percentDiffForMaxScale indicate the change 286 * required to reach top scale. 287 * @param greenForIncrease an increase since previousDataset will be 288 * displayed in green (decrease red) if true. 289 * @param legend a flag specifying whether or not a legend is required. 290 * @param tooltips configure chart to generate tool tips? 291 * @param locale the locale ({@code null} not permitted). 292 * @param subTitle displays a subtitle with colour scheme if true 293 * @param showDifference create a new dataset that will show the % 294 * difference between the two datasets. 295 * 296 * @return A pie chart. 297 */ 298 public static JFreeChart createPieChart(String title, PieDataset dataset, 299 PieDataset previousDataset, int percentDiffForMaxScale, 300 boolean greenForIncrease, boolean legend, boolean tooltips, 301 Locale locale, boolean subTitle, boolean showDifference) { 302 303 PiePlot plot = new PiePlot(dataset); 304 plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); 305 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); 306 307 if (tooltips) { 308 plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); 309 } 310 311 List keys = dataset.getKeys(); 312 DefaultPieDataset series = null; 313 if (showDifference) { 314 series = new DefaultPieDataset(); 315 } 316 317 double colorPerPercent = 255.0 / percentDiffForMaxScale; 318 for (Iterator it = keys.iterator(); it.hasNext();) { 319 Comparable key = (Comparable) it.next(); 320 Number newValue = dataset.getValue(key); 321 Number oldValue = previousDataset.getValue(key); 322 323 if (oldValue == null) { 324 if (greenForIncrease) { 325 plot.setSectionPaint(key, Color.GREEN); 326 } 327 else { 328 plot.setSectionPaint(key, Color.RED); 329 } 330 if (showDifference) { 331 assert series != null; // suppresses compiler warning 332 series.setValue(key + " (+100%)", newValue); 333 } 334 } 335 else { 336 double percentChange = (newValue.doubleValue() 337 / oldValue.doubleValue() - 1.0) * 100.0; 338 double shade 339 = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 340 : Math.abs(percentChange) * colorPerPercent); 341 if (greenForIncrease 342 && newValue.doubleValue() > oldValue.doubleValue() 343 || !greenForIncrease && newValue.doubleValue() 344 < oldValue.doubleValue()) { 345 plot.setSectionPaint(key, new Color(0, (int) shade, 0)); 346 } 347 else { 348 plot.setSectionPaint(key, new Color((int) shade, 0, 0)); 349 } 350 if (showDifference) { 351 assert series != null; // suppresses compiler warning 352 series.setValue(key + " (" + (percentChange >= 0 ? "+" : "") 353 + NumberFormat.getPercentInstance().format( 354 percentChange / 100.0) + ")", newValue); 355 } 356 } 357 } 358 359 if (showDifference) { 360 plot.setDataset(series); 361 } 362 363 JFreeChart chart = new JFreeChart(title, 364 JFreeChart.DEFAULT_TITLE_FONT, plot, legend); 365 366 if (subTitle) { 367 TextTitle subtitle = new TextTitle("Bright " + (greenForIncrease 368 ? "red" : "green") + "=change >=-" + percentDiffForMaxScale 369 + "%, Bright " + (!greenForIncrease ? "red" : "green") 370 + "=change >=+" + percentDiffForMaxScale + "%", 371 new Font("SansSerif", Font.PLAIN, 10)); 372 chart.addSubtitle(subtitle); 373 } 374 currentTheme.apply(chart); 375 return chart; 376 } 377 378 /** 379 * Creates a pie chart with default settings that compares 2 datasets. 380 * The colour of each section will be determined by the move from the value 381 * for the same key in {@code previousDataset}. ie if value1 > 382 * value2 then the section will be in green (unless 383 * {@code greenForIncrease} is {@code false}, in which case it 384 * would be {@code red}). Each section can have a shade of red or 385 * green as the difference can be tailored between 0% (black) and 386 * percentDiffForMaxScale% (bright red/green). 387 * <p> 388 * For instance if {@code percentDiffForMaxScale} is 10 (10%), a 389 * difference of 5% will have a half shade of red/green, a difference of 390 * 10% or more will have a maximum shade/brightness of red/green. 391 * <P> 392 * The chart object returned by this method uses a {@link PiePlot} instance 393 * as the plot. 394 * <p> 395 * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit 396 * Xhenseval</a>. 397 * 398 * @param title the chart title ({@code null} permitted). 399 * @param dataset the dataset for the chart ({@code null} permitted). 400 * @param previousDataset the dataset for the last run, this will be used 401 * to compare each key in the dataset 402 * @param percentDiffForMaxScale scale goes from bright red/green to black, 403 * percentDiffForMaxScale indicate the change 404 * required to reach top scale. 405 * @param greenForIncrease an increase since previousDataset will be 406 * displayed in green (decrease red) if true. 407 * @param legend a flag specifying whether or not a legend is required. 408 * @param tooltips configure chart to generate tool tips? 409 * @param urls configure chart to generate URLs? 410 * @param subTitle displays a subtitle with colour scheme if true 411 * @param showDifference create a new dataset that will show the % 412 * difference between the two datasets. 413 * 414 * @return A pie chart. 415 */ 416 public static JFreeChart createPieChart(String title, PieDataset dataset, 417 PieDataset previousDataset, int percentDiffForMaxScale, 418 boolean greenForIncrease, boolean legend, boolean tooltips, 419 boolean urls, boolean subTitle, boolean showDifference) { 420 421 PiePlot plot = new PiePlot(dataset); 422 plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); 423 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); 424 425 if (tooltips) { 426 plot.setToolTipGenerator(new StandardPieToolTipGenerator()); 427 } 428 if (urls) { 429 plot.setURLGenerator(new StandardPieURLGenerator()); 430 } 431 432 List keys = dataset.getKeys(); 433 DefaultPieDataset series = null; 434 if (showDifference) { 435 series = new DefaultPieDataset(); 436 } 437 438 double colorPerPercent = 255.0 / percentDiffForMaxScale; 439 for (Iterator it = keys.iterator(); it.hasNext();) { 440 Comparable key = (Comparable) it.next(); 441 Number newValue = dataset.getValue(key); 442 Number oldValue = previousDataset.getValue(key); 443 444 if (oldValue == null) { 445 if (greenForIncrease) { 446 plot.setSectionPaint(key, Color.GREEN); 447 } 448 else { 449 plot.setSectionPaint(key, Color.RED); 450 } 451 if (showDifference) { 452 assert series != null; // suppresses compiler warning 453 series.setValue(key + " (+100%)", newValue); 454 } 455 } 456 else { 457 double percentChange = (newValue.doubleValue() 458 / oldValue.doubleValue() - 1.0) * 100.0; 459 double shade 460 = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 461 : Math.abs(percentChange) * colorPerPercent); 462 if (greenForIncrease 463 && newValue.doubleValue() > oldValue.doubleValue() 464 || !greenForIncrease && newValue.doubleValue() 465 < oldValue.doubleValue()) { 466 plot.setSectionPaint(key, new Color(0, (int) shade, 0)); 467 } 468 else { 469 plot.setSectionPaint(key, new Color((int) shade, 0, 0)); 470 } 471 if (showDifference) { 472 assert series != null; // suppresses compiler warning 473 series.setValue(key + " (" + (percentChange >= 0 ? "+" : "") 474 + NumberFormat.getPercentInstance().format( 475 percentChange / 100.0) + ")", newValue); 476 } 477 } 478 } 479 480 if (showDifference) { 481 plot.setDataset(series); 482 } 483 484 JFreeChart chart = new JFreeChart(title, 485 JFreeChart.DEFAULT_TITLE_FONT, plot, legend); 486 487 if (subTitle) { 488 TextTitle subtitle = new TextTitle("Bright " + (greenForIncrease 489 ? "red" : "green") + "=change >=-" + percentDiffForMaxScale 490 + "%, Bright " + (!greenForIncrease ? "red" : "green") 491 + "=change >=+" + percentDiffForMaxScale + "%", 492 new Font("SansSerif", Font.PLAIN, 10)); 493 chart.addSubtitle(subtitle); 494 } 495 currentTheme.apply(chart); 496 return chart; 497 } 498 499 /** 500 * Creates a ring chart with default settings. 501 * <P> 502 * The chart object returned by this method uses a {@link RingPlot} 503 * instance as the plot. 504 * 505 * @param title the chart title ({@code null} permitted). 506 * @param dataset the dataset for the chart ({@code null} permitted). 507 * @param legend a flag specifying whether or not a legend is required. 508 * @param tooltips configure chart to generate tool tips? 509 * @param locale the locale ({@code null} not permitted). 510 * 511 * @return A ring chart. 512 */ 513 public static JFreeChart createRingChart(String title, PieDataset dataset, 514 boolean legend, boolean tooltips, Locale locale) { 515 516 RingPlot plot = new RingPlot(dataset); 517 plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); 518 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); 519 if (tooltips) { 520 plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); 521 } 522 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 523 plot, legend); 524 currentTheme.apply(chart); 525 return chart; 526 } 527 528 /** 529 * Creates a ring chart with default settings. 530 * <P> 531 * The chart object returned by this method uses a {@link RingPlot} 532 * instance as the plot. 533 * 534 * @param title the chart title ({@code null} permitted). 535 * @param dataset the dataset for the chart ({@code null} permitted). 536 * @param legend a flag specifying whether or not a legend is required. 537 * @param tooltips configure chart to generate tool tips? 538 * @param urls configure chart to generate URLs? 539 * 540 * @return A ring chart. 541 */ 542 public static JFreeChart createRingChart(String title, PieDataset dataset, 543 boolean legend, boolean tooltips, boolean urls) { 544 545 RingPlot plot = new RingPlot(dataset); 546 plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); 547 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); 548 if (tooltips) { 549 plot.setToolTipGenerator(new StandardPieToolTipGenerator()); 550 } 551 if (urls) { 552 plot.setURLGenerator(new StandardPieURLGenerator()); 553 } 554 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 555 plot, legend); 556 currentTheme.apply(chart); 557 return chart; 558 559 } 560 561 /** 562 * Creates a chart that displays multiple pie plots. The chart object 563 * returned by this method uses a {@link MultiplePiePlot} instance as the 564 * plot. 565 * 566 * @param title the chart title ({@code null} permitted). 567 * @param dataset the dataset ({@code null} permitted). 568 * @param order the order that the data is extracted (by row or by column) 569 * ({@code null} not permitted). 570 * @param legend include a legend? 571 * @param tooltips generate tooltips? 572 * @param urls generate URLs? 573 * 574 * @return A chart. 575 */ 576 public static JFreeChart createMultiplePieChart(String title, 577 CategoryDataset dataset, TableOrder order, boolean legend, 578 boolean tooltips, boolean urls) { 579 580 Args.nullNotPermitted(order, "order"); 581 MultiplePiePlot plot = new MultiplePiePlot(dataset); 582 plot.setDataExtractOrder(order); 583 plot.setBackgroundPaint(null); 584 plot.setOutlineStroke(null); 585 586 if (tooltips) { 587 PieToolTipGenerator tooltipGenerator 588 = new StandardPieToolTipGenerator(); 589 PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); 590 pp.setToolTipGenerator(tooltipGenerator); 591 } 592 593 if (urls) { 594 PieURLGenerator urlGenerator = new StandardPieURLGenerator(); 595 PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); 596 pp.setURLGenerator(urlGenerator); 597 } 598 599 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 600 plot, legend); 601 currentTheme.apply(chart); 602 return chart; 603 604 } 605 606 /** 607 * Creates a bar chart with a vertical orientation. The chart object 608 * returned by this method uses a {@link CategoryPlot} instance as the 609 * plot, with a {@link CategoryAxis} for the domain axis, a 610 * {@link NumberAxis} as the range axis, and a {@link BarRenderer} as the 611 * renderer. 612 * 613 * @param title the chart title ({@code null} permitted). 614 * @param categoryAxisLabel the label for the category axis 615 * ({@code null} permitted). 616 * @param valueAxisLabel the label for the value axis 617 * ({@code null} permitted). 618 * @param dataset the dataset for the chart ({@code null} permitted). 619 * 620 * @return A bar chart. 621 */ 622 public static JFreeChart createBarChart(String title, 623 String categoryAxisLabel, String valueAxisLabel, 624 CategoryDataset dataset) { 625 return createBarChart(title, categoryAxisLabel, valueAxisLabel, dataset, 626 PlotOrientation.VERTICAL, true, true, false); 627 } 628 629 /** 630 * Creates a bar chart. The chart object returned by this method uses a 631 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis} 632 * for the domain axis, a {@link NumberAxis} as the range axis, and a 633 * {@link BarRenderer} as the renderer. 634 * 635 * @param title the chart title ({@code null} permitted). 636 * @param categoryAxisLabel the label for the category axis 637 * ({@code null} permitted). 638 * @param valueAxisLabel the label for the value axis 639 * ({@code null} permitted). 640 * @param dataset the dataset for the chart ({@code null} permitted). 641 * @param orientation the plot orientation (horizontal or vertical) 642 * ({@code null} not 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 bar chart. 648 */ 649 public static JFreeChart createBarChart(String title, 650 String categoryAxisLabel, String valueAxisLabel, 651 CategoryDataset dataset, PlotOrientation orientation, 652 boolean legend, boolean tooltips, boolean urls) { 653 654 Args.nullNotPermitted(orientation, "orientation"); 655 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 656 ValueAxis valueAxis = new NumberAxis(valueAxisLabel); 657 658 BarRenderer renderer = new BarRenderer(); 659 if (orientation == PlotOrientation.HORIZONTAL) { 660 ItemLabelPosition position1 = new ItemLabelPosition( 661 ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); 662 renderer.setDefaultPositiveItemLabelPosition(position1); 663 ItemLabelPosition position2 = new ItemLabelPosition( 664 ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); 665 renderer.setDefaultNegativeItemLabelPosition(position2); 666 } else if (orientation == PlotOrientation.VERTICAL) { 667 ItemLabelPosition position1 = new ItemLabelPosition( 668 ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); 669 renderer.setDefaultPositiveItemLabelPosition(position1); 670 ItemLabelPosition position2 = new ItemLabelPosition( 671 ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); 672 renderer.setDefaultNegativeItemLabelPosition(position2); 673 } 674 if (tooltips) { 675 renderer.setDefaultToolTipGenerator( 676 new StandardCategoryToolTipGenerator()); 677 } 678 if (urls) { 679 renderer.setDefaultItemURLGenerator( 680 new StandardCategoryURLGenerator()); 681 } 682 683 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 684 renderer); 685 plot.setOrientation(orientation); 686 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 687 plot, legend); 688 currentTheme.apply(chart); 689 return chart; 690 691 } 692 693 /** 694 * Creates a stacked bar chart with default settings. The chart object 695 * returned by this method uses a {@link CategoryPlot} instance as the 696 * plot, with a {@link CategoryAxis} for the domain axis, a 697 * {@link NumberAxis} as the range axis, and a {@link StackedBarRenderer} 698 * as the renderer. 699 * 700 * @param title the chart title ({@code null} permitted). 701 * @param domainAxisLabel the label for the category axis 702 * ({@code null} permitted). 703 * @param rangeAxisLabel the label for the value axis 704 * ({@code null} permitted). 705 * @param dataset the dataset for the chart ({@code null} permitted). 706 * 707 * @return A stacked bar chart. 708 */ 709 public static JFreeChart createStackedBarChart(String title, 710 String domainAxisLabel, String rangeAxisLabel, 711 CategoryDataset dataset) { 712 return createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, 713 dataset, PlotOrientation.VERTICAL, true, true, false); 714 } 715 716 /** 717 * Creates a stacked bar chart with default settings. The chart object 718 * returned by this method uses a {@link CategoryPlot} instance as the 719 * plot, with a {@link CategoryAxis} for the domain axis, a 720 * {@link NumberAxis} as the range axis, and a {@link StackedBarRenderer} 721 * as the renderer. 722 * 723 * @param title the chart title ({@code null} permitted). 724 * @param domainAxisLabel the label for the category axis 725 * ({@code null} permitted). 726 * @param rangeAxisLabel the label for the value axis 727 * ({@code null} permitted). 728 * @param dataset the dataset for the chart ({@code null} permitted). 729 * @param orientation the orientation of the chart (horizontal or 730 * vertical) ({@code null} not permitted). 731 * @param legend a flag specifying whether or not a legend is required. 732 * @param tooltips configure chart to generate tool tips? 733 * @param urls configure chart to generate URLs? 734 * 735 * @return A stacked bar chart. 736 */ 737 public static JFreeChart createStackedBarChart(String title, 738 String domainAxisLabel, String rangeAxisLabel, 739 CategoryDataset dataset, PlotOrientation orientation, 740 boolean legend, boolean tooltips, boolean urls) { 741 742 Args.nullNotPermitted(orientation, "orientation"); 743 744 CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel); 745 ValueAxis valueAxis = new NumberAxis(rangeAxisLabel); 746 747 StackedBarRenderer renderer = new StackedBarRenderer(); 748 if (tooltips) { 749 renderer.setDefaultToolTipGenerator( 750 new StandardCategoryToolTipGenerator()); 751 } 752 if (urls) { 753 renderer.setDefaultItemURLGenerator( 754 new StandardCategoryURLGenerator()); 755 } 756 757 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 758 renderer); 759 plot.setOrientation(orientation); 760 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 761 plot, legend); 762 currentTheme.apply(chart); 763 return chart; 764 765 } 766 767 /** 768 * Creates an area chart with default settings. The chart object returned 769 * by this method uses a {@link CategoryPlot} instance as the plot, with a 770 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the 771 * range axis, and an {@link AreaRenderer} as the renderer. 772 * 773 * @param title the chart title ({@code null} permitted). 774 * @param categoryAxisLabel the label for the category axis 775 * ({@code null} permitted). 776 * @param valueAxisLabel the label for the value axis ({@code null} 777 * permitted). 778 * @param dataset the dataset for the chart ({@code null} permitted). 779 * 780 * @return An area chart. 781 */ 782 public static JFreeChart createAreaChart(String title, 783 String categoryAxisLabel, String valueAxisLabel, 784 CategoryDataset dataset) { 785 return createAreaChart(title, categoryAxisLabel, valueAxisLabel, 786 dataset, PlotOrientation.VERTICAL, true, true, false); 787 } 788 789 /** 790 * Creates an area chart with default settings. The chart object returned 791 * by this method uses a {@link CategoryPlot} instance as the plot, with a 792 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the 793 * range axis, and an {@link AreaRenderer} as the renderer. 794 * 795 * @param title the chart title ({@code null} permitted). 796 * @param categoryAxisLabel the label for the category axis 797 * ({@code null} permitted). 798 * @param valueAxisLabel the label for the value axis ({@code null} 799 * permitted). 800 * @param dataset the dataset for the chart ({@code null} permitted). 801 * @param orientation the plot orientation ({@code null} not 802 * permitted). 803 * @param legend a flag specifying whether or not a legend is required. 804 * @param tooltips configure chart to generate tool tips? 805 * @param urls configure chart to generate URLs? 806 * 807 * @return An area chart. 808 */ 809 public static JFreeChart createAreaChart(String title, 810 String categoryAxisLabel, String valueAxisLabel, 811 CategoryDataset dataset, PlotOrientation orientation, 812 boolean legend, boolean tooltips, boolean urls) { 813 814 Args.nullNotPermitted(orientation, "orientation"); 815 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 816 categoryAxis.setCategoryMargin(0.0); 817 818 ValueAxis valueAxis = new NumberAxis(valueAxisLabel); 819 820 AreaRenderer renderer = new AreaRenderer(); 821 if (tooltips) { 822 renderer.setDefaultToolTipGenerator( 823 new StandardCategoryToolTipGenerator()); 824 } 825 if (urls) { 826 renderer.setDefaultItemURLGenerator( 827 new StandardCategoryURLGenerator()); 828 } 829 830 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 831 renderer); 832 plot.setOrientation(orientation); 833 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 834 plot, legend); 835 currentTheme.apply(chart); 836 return chart; 837 838 } 839 840 /** 841 * Creates a stacked area chart with default settings. The chart object 842 * returned by this method uses a {@link CategoryPlot} instance as the 843 * plot, with a {@link CategoryAxis} for the domain axis, a 844 * {@link NumberAxis} as the range axis, and a {@link StackedAreaRenderer} 845 * as the renderer. 846 * 847 * @param title the chart title ({@code null} permitted). 848 * @param categoryAxisLabel the label for the category axis 849 * ({@code null} permitted). 850 * @param valueAxisLabel the label for the value axis ({@code null} 851 * permitted). 852 * @param dataset the dataset for the chart ({@code null} permitted). 853 * 854 * @return A stacked area chart. 855 */ 856 public static JFreeChart createStackedAreaChart(String title, 857 String categoryAxisLabel, String valueAxisLabel, 858 CategoryDataset dataset) { 859 return createStackedAreaChart(title, categoryAxisLabel, valueAxisLabel, 860 dataset, PlotOrientation.VERTICAL, true, true, false); 861 } 862 863 /** 864 * Creates a stacked area chart with default settings. The chart object 865 * returned by this method uses a {@link CategoryPlot} instance as the 866 * plot, with a {@link CategoryAxis} for the domain axis, a 867 * {@link NumberAxis} as the range axis, and a {@link StackedAreaRenderer} 868 * as the renderer. 869 * 870 * @param title the chart title ({@code null} permitted). 871 * @param categoryAxisLabel the label for the category axis 872 * ({@code null} permitted). 873 * @param valueAxisLabel the label for the value axis ({@code null} 874 * permitted). 875 * @param dataset the dataset for the chart ({@code null} permitted). 876 * @param orientation the plot orientation (horizontal or vertical) 877 * ({@code null} not permitted). 878 * @param legend a flag specifying whether or not a legend is required. 879 * @param tooltips configure chart to generate tool tips? 880 * @param urls configure chart to generate URLs? 881 * 882 * @return A stacked area chart. 883 */ 884 public static JFreeChart createStackedAreaChart(String title, 885 String categoryAxisLabel, String valueAxisLabel, 886 CategoryDataset dataset, PlotOrientation orientation, 887 boolean legend, boolean tooltips, boolean urls) { 888 889 Args.nullNotPermitted(orientation, "orientation"); 890 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 891 categoryAxis.setCategoryMargin(0.0); 892 ValueAxis valueAxis = new NumberAxis(valueAxisLabel); 893 894 StackedAreaRenderer renderer = new StackedAreaRenderer(); 895 if (tooltips) { 896 renderer.setDefaultToolTipGenerator( 897 new StandardCategoryToolTipGenerator()); 898 } 899 if (urls) { 900 renderer.setDefaultItemURLGenerator( 901 new StandardCategoryURLGenerator()); 902 } 903 904 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 905 renderer); 906 plot.setOrientation(orientation); 907 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 908 plot, legend); 909 currentTheme.apply(chart); 910 return chart; 911 912 } 913 914 /** 915 * Creates a line chart with default settings. The chart object returned 916 * by this method uses a {@link CategoryPlot} instance as the plot, with a 917 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the 918 * range axis, and a {@link LineAndShapeRenderer} as the renderer. 919 * 920 * @param title the chart title ({@code null} permitted). 921 * @param categoryAxisLabel the label for the category axis 922 * ({@code null} permitted). 923 * @param valueAxisLabel the label for the value axis ({@code null} 924 * permitted). 925 * @param dataset the dataset for the chart ({@code null} permitted). 926 * 927 * @return A line chart. 928 */ 929 public static JFreeChart createLineChart(String title, 930 String categoryAxisLabel, String valueAxisLabel, 931 CategoryDataset dataset) { 932 return createLineChart(title, categoryAxisLabel, valueAxisLabel, 933 dataset, PlotOrientation.VERTICAL, true, true, false); 934 } 935 936 /** 937 * Creates a line chart with default settings. The chart object returned 938 * by this method uses a {@link CategoryPlot} instance as the plot, with a 939 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the 940 * range axis, and a {@link LineAndShapeRenderer} as the renderer. 941 * 942 * @param title the chart title ({@code null} permitted). 943 * @param categoryAxisLabel the label for the category axis 944 * ({@code null} permitted). 945 * @param valueAxisLabel the label for the value axis ({@code null} 946 * permitted). 947 * @param dataset the dataset for the chart ({@code null} permitted). 948 * @param orientation the chart orientation (horizontal or vertical) 949 * ({@code null} not permitted). 950 * @param legend a flag specifying whether or not a legend is required. 951 * @param tooltips configure chart to generate tool tips? 952 * @param urls configure chart to generate URLs? 953 * 954 * @return A line chart. 955 */ 956 public static JFreeChart createLineChart(String title, 957 String categoryAxisLabel, String valueAxisLabel, 958 CategoryDataset dataset, PlotOrientation orientation, 959 boolean legend, boolean tooltips, boolean urls) { 960 961 Args.nullNotPermitted(orientation, "orientation"); 962 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 963 ValueAxis valueAxis = new NumberAxis(valueAxisLabel); 964 965 LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false); 966 if (tooltips) { 967 renderer.setDefaultToolTipGenerator( 968 new StandardCategoryToolTipGenerator()); 969 } 970 if (urls) { 971 renderer.setDefaultItemURLGenerator( 972 new StandardCategoryURLGenerator()); 973 } 974 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 975 renderer); 976 plot.setOrientation(orientation); 977 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 978 plot, legend); 979 currentTheme.apply(chart); 980 return chart; 981 982 } 983 984 /** 985 * Creates a Gantt chart using the supplied attributes plus default values 986 * where required. The chart object returned by this method uses a 987 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis} 988 * for the domain axis, a {@link DateAxis} as the range axis, and a 989 * {@link GanttRenderer} as the renderer. 990 * 991 * @param title the chart title ({@code null} permitted). 992 * @param categoryAxisLabel the label for the category axis 993 * ({@code null} permitted). 994 * @param dateAxisLabel the label for the date axis 995 * ({@code null} permitted). 996 * @param dataset the dataset for the chart ({@code null} permitted). 997 * 998 * @return A Gantt chart. 999 */ 1000 public static JFreeChart createGanttChart(String title, 1001 String categoryAxisLabel, String dateAxisLabel, 1002 IntervalCategoryDataset dataset) { 1003 return createGanttChart(title, categoryAxisLabel, dateAxisLabel, 1004 dataset, true, true, false); 1005 } 1006 1007 /** 1008 * Creates a Gantt chart using the supplied attributes plus default values 1009 * where required. The chart object returned by this method uses a 1010 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis} 1011 * for the domain axis, a {@link DateAxis} as the range axis, and a 1012 * {@link GanttRenderer} as the renderer. 1013 * 1014 * @param title the chart title ({@code null} permitted). 1015 * @param categoryAxisLabel the label for the category axis 1016 * ({@code null} permitted). 1017 * @param dateAxisLabel the label for the date axis 1018 * ({@code null} permitted). 1019 * @param dataset the dataset for the chart ({@code null} permitted). 1020 * @param legend a flag specifying whether or not a legend is required. 1021 * @param tooltips configure chart to generate tool tips? 1022 * @param urls configure chart to generate URLs? 1023 * 1024 * @return A Gantt chart. 1025 */ 1026 public static JFreeChart createGanttChart(String title, 1027 String categoryAxisLabel, String dateAxisLabel, 1028 IntervalCategoryDataset dataset, boolean legend, boolean tooltips, 1029 boolean urls) { 1030 1031 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 1032 DateAxis dateAxis = new DateAxis(dateAxisLabel); 1033 1034 CategoryItemRenderer renderer = new GanttRenderer(); 1035 if (tooltips) { 1036 renderer.setDefaultToolTipGenerator( 1037 new IntervalCategoryToolTipGenerator( 1038 "{3} - {4}", DateFormat.getDateInstance())); 1039 } 1040 if (urls) { 1041 renderer.setDefaultItemURLGenerator( 1042 new StandardCategoryURLGenerator()); 1043 } 1044 1045 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, dateAxis, 1046 renderer); 1047 plot.setOrientation(PlotOrientation.HORIZONTAL); 1048 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1049 plot, legend); 1050 currentTheme.apply(chart); 1051 return chart; 1052 1053 } 1054 1055 /** 1056 * Creates a waterfall chart. The chart object returned by this method 1057 * uses a {@link CategoryPlot} instance as the plot, with a 1058 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the 1059 * range axis, and a {@link WaterfallBarRenderer} as the renderer. 1060 * 1061 * @param title the chart title ({@code null} permitted). 1062 * @param categoryAxisLabel the label for the category axis 1063 * ({@code null} permitted). 1064 * @param valueAxisLabel the label for the value axis ({@code null} 1065 * permitted). 1066 * @param dataset the dataset for the chart ({@code null} permitted). 1067 * @param orientation the plot orientation (horizontal or vertical) 1068 * ({@code null} NOT permitted). 1069 * @param legend a flag specifying whether or not a legend is required. 1070 * @param tooltips configure chart to generate tool tips? 1071 * @param urls configure chart to generate URLs? 1072 * 1073 * @return A waterfall chart. 1074 */ 1075 public static JFreeChart createWaterfallChart(String title, 1076 String categoryAxisLabel, String valueAxisLabel, 1077 CategoryDataset dataset, PlotOrientation orientation, 1078 boolean legend, boolean tooltips, boolean urls) { 1079 1080 Args.nullNotPermitted(orientation, "orientation"); 1081 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 1082 categoryAxis.setCategoryMargin(0.0); 1083 1084 ValueAxis valueAxis = new NumberAxis(valueAxisLabel); 1085 1086 WaterfallBarRenderer renderer = new WaterfallBarRenderer(); 1087 if (orientation == PlotOrientation.HORIZONTAL) { 1088 ItemLabelPosition position = new ItemLabelPosition( 1089 ItemLabelAnchor.CENTER, TextAnchor.CENTER, 1090 TextAnchor.CENTER, Math.PI / 2.0); 1091 renderer.setDefaultPositiveItemLabelPosition(position); 1092 renderer.setDefaultNegativeItemLabelPosition(position); 1093 } 1094 else if (orientation == PlotOrientation.VERTICAL) { 1095 ItemLabelPosition position = new ItemLabelPosition( 1096 ItemLabelAnchor.CENTER, TextAnchor.CENTER, 1097 TextAnchor.CENTER, 0.0); 1098 renderer.setDefaultPositiveItemLabelPosition(position); 1099 renderer.setDefaultNegativeItemLabelPosition(position); 1100 } 1101 if (tooltips) { 1102 StandardCategoryToolTipGenerator generator 1103 = new StandardCategoryToolTipGenerator(); 1104 renderer.setDefaultToolTipGenerator(generator); 1105 } 1106 if (urls) { 1107 renderer.setDefaultItemURLGenerator( 1108 new StandardCategoryURLGenerator()); 1109 } 1110 1111 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 1112 renderer); 1113 plot.clearRangeMarkers(); 1114 Marker baseline = new ValueMarker(0.0); 1115 baseline.setPaint(Color.BLACK); 1116 plot.addRangeMarker(baseline, Layer.FOREGROUND); 1117 plot.setOrientation(orientation); 1118 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1119 plot, legend); 1120 currentTheme.apply(chart); 1121 return chart; 1122 1123 } 1124 1125 /** 1126 * Creates a polar plot for the specified dataset (x-values interpreted as 1127 * angles in degrees). The chart object returned by this method uses a 1128 * {@link PolarPlot} instance as the plot, with a {@link NumberAxis} for 1129 * the radial axis. 1130 * 1131 * @param title the chart title ({@code null} permitted). 1132 * @param dataset the dataset ({@code null} permitted). 1133 * @param legend legend required? 1134 * @param tooltips tooltips required? 1135 * @param urls URLs required? 1136 * 1137 * @return A chart. 1138 */ 1139 public static JFreeChart createPolarChart(String title, XYDataset dataset, 1140 boolean legend, boolean tooltips, boolean urls) { 1141 1142 PolarPlot plot = new PolarPlot(); 1143 plot.setDataset(dataset); 1144 NumberAxis rangeAxis = new NumberAxis(); 1145 rangeAxis.setAxisLineVisible(false); 1146 rangeAxis.setTickMarksVisible(false); 1147 rangeAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); 1148 plot.setAxis(rangeAxis); 1149 plot.setRenderer(new DefaultPolarItemRenderer()); 1150 JFreeChart chart = new JFreeChart( 1151 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); 1152 currentTheme.apply(chart); 1153 return chart; 1154 1155 } 1156 1157 /** 1158 * Creates a scatter plot with default settings. The chart object 1159 * returned by this method uses an {@link XYPlot} instance as the plot, 1160 * with a {@link NumberAxis} for the domain axis, a {@link NumberAxis} 1161 * as the range axis, and an {@link XYLineAndShapeRenderer} as the 1162 * renderer. 1163 * 1164 * @param title the chart title ({@code null} permitted). 1165 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1166 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1167 * @param dataset the dataset for the chart ({@code null} permitted). 1168 * 1169 * @return A scatter plot. 1170 */ 1171 public static JFreeChart createScatterPlot(String title, String xAxisLabel, 1172 String yAxisLabel, XYDataset dataset) { 1173 return createScatterPlot(title, xAxisLabel, yAxisLabel, dataset, 1174 PlotOrientation.VERTICAL, true, true, false); 1175 } 1176 1177 /** 1178 * Creates a scatter plot with default settings. The chart object 1179 * returned by this method uses an {@link XYPlot} instance as the plot, 1180 * with a {@link NumberAxis} for the domain axis, a {@link NumberAxis} 1181 * as the range axis, and an {@link XYLineAndShapeRenderer} as the 1182 * renderer. 1183 * 1184 * @param title the chart title ({@code null} permitted). 1185 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1186 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1187 * @param dataset the dataset for the chart ({@code null} permitted). 1188 * @param orientation the plot orientation (horizontal or vertical) 1189 * ({@code null} NOT permitted). 1190 * @param legend a flag specifying whether or not a legend is required. 1191 * @param tooltips configure chart to generate tool tips? 1192 * @param urls configure chart to generate URLs? 1193 * 1194 * @return A scatter plot. 1195 */ 1196 public static JFreeChart createScatterPlot(String title, String xAxisLabel, 1197 String yAxisLabel, XYDataset dataset, PlotOrientation orientation, 1198 boolean legend, boolean tooltips, boolean urls) { 1199 1200 Args.nullNotPermitted(orientation, "orientation"); 1201 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1202 xAxis.setAutoRangeIncludesZero(false); 1203 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1204 yAxis.setAutoRangeIncludesZero(false); 1205 1206 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1207 1208 XYToolTipGenerator toolTipGenerator = null; 1209 if (tooltips) { 1210 toolTipGenerator = new StandardXYToolTipGenerator(); 1211 } 1212 1213 XYURLGenerator urlGenerator = null; 1214 if (urls) { 1215 urlGenerator = new StandardXYURLGenerator(); 1216 } 1217 XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true); 1218 renderer.setDefaultToolTipGenerator(toolTipGenerator); 1219 renderer.setURLGenerator(urlGenerator); 1220 plot.setRenderer(renderer); 1221 plot.setOrientation(orientation); 1222 1223 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1224 plot, legend); 1225 currentTheme.apply(chart); 1226 return chart; 1227 1228 } 1229 1230 /** 1231 * Creates and returns a default instance of an XY bar chart. 1232 * <P> 1233 * The chart object returned by this method uses an {@link XYPlot} instance 1234 * as the plot, with a {@link DateAxis} for the domain axis, a 1235 * {@link NumberAxis} as the range axis, and a {@link XYBarRenderer} as the 1236 * renderer. 1237 * 1238 * @param title the chart title ({@code null} permitted). 1239 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1240 * @param dateAxis make the domain axis display dates? 1241 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1242 * @param dataset the dataset for the chart ({@code null} permitted). 1243 * 1244 * @return An XY bar chart. 1245 */ 1246 public static JFreeChart createXYBarChart(String title, String xAxisLabel, 1247 boolean dateAxis, String yAxisLabel, IntervalXYDataset dataset) { 1248 return createXYBarChart(title, xAxisLabel, dateAxis, yAxisLabel, 1249 dataset, PlotOrientation.VERTICAL, true, true, false); 1250 } 1251 1252 /** 1253 * Creates and returns a default instance of an XY bar chart. 1254 * <P> 1255 * The chart object returned by this method uses an {@link XYPlot} instance 1256 * as the plot, with a {@link DateAxis} for the domain axis, a 1257 * {@link NumberAxis} as the range axis, and a {@link XYBarRenderer} as the 1258 * renderer. 1259 * 1260 * @param title the chart title ({@code null} permitted). 1261 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1262 * @param dateAxis make the domain axis display dates? 1263 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1264 * @param dataset the dataset for the chart ({@code null} permitted). 1265 * @param orientation the orientation (horizontal or vertical) 1266 * ({@code null} NOT permitted). 1267 * @param legend a flag specifying whether or not a legend is required. 1268 * @param tooltips configure chart to generate tool tips? 1269 * @param urls configure chart to generate URLs? 1270 * 1271 * @return An XY bar chart. 1272 */ 1273 public static JFreeChart createXYBarChart(String title, String xAxisLabel, 1274 boolean dateAxis, String yAxisLabel, IntervalXYDataset dataset, 1275 PlotOrientation orientation, boolean legend, boolean tooltips, 1276 boolean urls) { 1277 1278 Args.nullNotPermitted(orientation, "orientation"); 1279 ValueAxis domainAxis; 1280 if (dateAxis) { 1281 domainAxis = new DateAxis(xAxisLabel); 1282 } 1283 else { 1284 NumberAxis axis = new NumberAxis(xAxisLabel); 1285 axis.setAutoRangeIncludesZero(false); 1286 domainAxis = axis; 1287 } 1288 ValueAxis valueAxis = new NumberAxis(yAxisLabel); 1289 1290 XYBarRenderer renderer = new XYBarRenderer(); 1291 if (tooltips) { 1292 XYToolTipGenerator tt; 1293 if (dateAxis) { 1294 tt = StandardXYToolTipGenerator.getTimeSeriesInstance(); 1295 } 1296 else { 1297 tt = new StandardXYToolTipGenerator(); 1298 } 1299 renderer.setDefaultToolTipGenerator(tt); 1300 } 1301 if (urls) { 1302 renderer.setURLGenerator(new StandardXYURLGenerator()); 1303 } 1304 1305 XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer); 1306 plot.setOrientation(orientation); 1307 1308 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1309 plot, legend); 1310 currentTheme.apply(chart); 1311 return chart; 1312 1313 } 1314 1315 /** 1316 * Creates an area chart using an {@link XYDataset}. 1317 * <P> 1318 * The chart object returned by this method uses an {@link XYPlot} instance 1319 * as the plot, with a {@link NumberAxis} for the domain axis, a 1320 * {@link NumberAxis} as the range axis, and a {@link XYAreaRenderer} as 1321 * the renderer. 1322 * 1323 * @param title the chart title ({@code null} permitted). 1324 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1325 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1326 * @param dataset the dataset for the chart ({@code null} permitted). 1327 * 1328 * @return An XY area chart. 1329 * 1330 * @param <S> the type for series keys. 1331 */ 1332 public static <S extends Comparable<S>> JFreeChart createXYAreaChart( 1333 String title,String xAxisLabel, String yAxisLabel, 1334 XYDataset<S> dataset) { 1335 return createXYAreaChart(title, xAxisLabel, yAxisLabel, dataset, 1336 PlotOrientation.VERTICAL, true, true, false); 1337 } 1338 1339 /** 1340 * Creates an area chart using an {@link XYDataset}. 1341 * <P> 1342 * The chart object returned by this method uses an {@link XYPlot} instance 1343 * as the plot, with a {@link NumberAxis} for the domain axis, a 1344 * {@link NumberAxis} as the range axis, and a {@link XYAreaRenderer} as 1345 * the renderer. 1346 * 1347 * @param title the chart title ({@code null} permitted). 1348 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1349 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1350 * @param dataset the dataset for the chart ({@code null} permitted). 1351 * @param orientation the plot orientation (horizontal or vertical) 1352 * ({@code null} NOT permitted). 1353 * @param legend a flag specifying whether or not a legend is required. 1354 * @param tooltips configure chart to generate tool tips? 1355 * @param urls configure chart to generate URLs? 1356 * 1357 * @param <S> the type for series keys. 1358 * 1359 * @return An XY area chart. 1360 */ 1361 public static <S extends Comparable<S>> JFreeChart createXYAreaChart( 1362 String title, String xAxisLabel, 1363 String yAxisLabel, XYDataset<S> dataset, PlotOrientation orientation, 1364 boolean legend, boolean tooltips, boolean urls) { 1365 1366 Args.nullNotPermitted(orientation, "orientation"); 1367 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1368 xAxis.setAutoRangeIncludesZero(false); 1369 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1370 XYPlot<S> plot = new XYPlot<>(dataset, xAxis, yAxis, null); 1371 plot.setOrientation(orientation); 1372 plot.setForegroundAlpha(0.5f); 1373 1374 XYToolTipGenerator tipGenerator = null; 1375 if (tooltips) { 1376 tipGenerator = new StandardXYToolTipGenerator(); 1377 } 1378 1379 XYURLGenerator urlGenerator = null; 1380 if (urls) { 1381 urlGenerator = new StandardXYURLGenerator(); 1382 } 1383 1384 plot.setRenderer(new XYAreaRenderer(XYAreaRenderer.AREA, tipGenerator, 1385 urlGenerator)); 1386 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1387 plot, legend); 1388 currentTheme.apply(chart); 1389 return chart; 1390 1391 } 1392 1393 /** 1394 * Creates a stacked XY area plot. The chart object returned by this 1395 * method uses an {@link XYPlot} instance as the plot, with a 1396 * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the 1397 * range axis, and a {@link StackedXYAreaRenderer2} as the renderer. 1398 * 1399 * @param title the chart title ({@code null} permitted). 1400 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1401 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1402 * @param dataset the dataset for the chart ({@code null} permitted). 1403 * 1404 * @return A stacked XY area chart. 1405 */ 1406 public static JFreeChart createStackedXYAreaChart(String title, 1407 String xAxisLabel, String yAxisLabel, TableXYDataset dataset) { 1408 return createStackedXYAreaChart(title, xAxisLabel, yAxisLabel, 1409 dataset, PlotOrientation.VERTICAL, true, true, false); 1410 } 1411 1412 /** 1413 * Creates a stacked XY area plot. The chart object returned by this 1414 * method uses an {@link XYPlot} instance as the plot, with a 1415 * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the 1416 * range axis, and a {@link StackedXYAreaRenderer2} as the renderer. 1417 * 1418 * @param title the chart title ({@code null} permitted). 1419 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1420 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1421 * @param dataset the dataset for the chart ({@code null} permitted). 1422 * @param orientation the plot orientation (horizontal or vertical) 1423 * ({@code null} NOT permitted). 1424 * @param legend a flag specifying whether or not a legend is required. 1425 * @param tooltips configure chart to generate tool tips? 1426 * @param urls configure chart to generate URLs? 1427 * 1428 * @return A stacked XY area chart. 1429 */ 1430 public static JFreeChart createStackedXYAreaChart(String title, 1431 String xAxisLabel, String yAxisLabel, TableXYDataset dataset, 1432 PlotOrientation orientation, boolean legend, boolean tooltips, 1433 boolean urls) { 1434 1435 Args.nullNotPermitted(orientation, "orientation"); 1436 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1437 xAxis.setAutoRangeIncludesZero(false); 1438 xAxis.setLowerMargin(0.0); 1439 xAxis.setUpperMargin(0.0); 1440 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1441 XYToolTipGenerator toolTipGenerator = null; 1442 if (tooltips) { 1443 toolTipGenerator = new StandardXYToolTipGenerator(); 1444 } 1445 1446 XYURLGenerator urlGenerator = null; 1447 if (urls) { 1448 urlGenerator = new StandardXYURLGenerator(); 1449 } 1450 StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2( 1451 toolTipGenerator, urlGenerator); 1452 renderer.setOutline(true); 1453 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 1454 plot.setOrientation(orientation); 1455 1456 plot.setRangeAxis(yAxis); // forces recalculation of the axis range 1457 1458 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1459 plot, legend); 1460 currentTheme.apply(chart); 1461 return chart; 1462 1463 } 1464 1465 /** 1466 * Creates a line chart (based on an {@link XYDataset}) with default 1467 * settings. 1468 * 1469 * @param title the chart title ({@code null} permitted). 1470 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1471 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1472 * @param dataset the dataset for the chart ({@code null} permitted). 1473 * 1474 * @return The chart. 1475 */ 1476 public static JFreeChart createXYLineChart(String title, 1477 String xAxisLabel, String yAxisLabel, XYDataset dataset) { 1478 return createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, 1479 PlotOrientation.VERTICAL, true, true, false); 1480 } 1481 1482 /** 1483 * Creates a line chart (based on an {@link XYDataset}) with default 1484 * settings. 1485 * 1486 * @param title the chart title ({@code null} permitted). 1487 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1488 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1489 * @param dataset the dataset for the chart ({@code null} permitted). 1490 * @param orientation the plot orientation (horizontal or vertical) 1491 * ({@code null} NOT permitted). 1492 * @param legend a flag specifying whether or not a legend is required. 1493 * @param tooltips configure chart to generate tool tips? 1494 * @param urls configure chart to generate URLs? 1495 * 1496 * @return The chart. 1497 */ 1498 public static JFreeChart createXYLineChart(String title, String xAxisLabel, 1499 String yAxisLabel, XYDataset dataset, PlotOrientation orientation, 1500 boolean legend, boolean tooltips, boolean urls) { 1501 1502 Args.nullNotPermitted(orientation, "orientation"); 1503 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1504 xAxis.setAutoRangeIncludesZero(false); 1505 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1506 XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); 1507 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 1508 plot.setOrientation(orientation); 1509 if (tooltips) { 1510 renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator()); 1511 } 1512 if (urls) { 1513 renderer.setURLGenerator(new StandardXYURLGenerator()); 1514 } 1515 JFreeChart chart = null; 1516 chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1517 plot, legend); 1518 currentTheme.apply(chart); 1519 return chart; 1520 1521 } 1522 1523 /** 1524 * Creates a stepped XY plot with default settings. 1525 * 1526 * @param title the chart title ({@code null} permitted). 1527 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1528 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1529 * @param dataset the dataset for the chart ({@code null} permitted). 1530 * 1531 * @return A chart. 1532 */ 1533 public static JFreeChart createXYStepChart(String title, String xAxisLabel, 1534 String yAxisLabel, XYDataset dataset) { 1535 return createXYStepChart(title, xAxisLabel, yAxisLabel, dataset, 1536 PlotOrientation.VERTICAL, true, true, false); 1537 } 1538 1539 /** 1540 * Creates a stepped XY plot with default settings. 1541 * 1542 * @param title the chart title ({@code null} permitted). 1543 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1544 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1545 * @param dataset the dataset for the chart ({@code null} permitted). 1546 * @param orientation the plot orientation (horizontal or vertical) 1547 * ({@code null} NOT permitted). 1548 * @param legend a flag specifying whether or not a legend is required. 1549 * @param tooltips configure chart to generate tool tips? 1550 * @param urls configure chart to generate URLs? 1551 * 1552 * @return A chart. 1553 */ 1554 public static JFreeChart createXYStepChart(String title, String xAxisLabel, 1555 String yAxisLabel, XYDataset dataset, PlotOrientation orientation, 1556 boolean legend, boolean tooltips, boolean urls) { 1557 1558 Args.nullNotPermitted(orientation, "orientation"); 1559 DateAxis xAxis = new DateAxis(xAxisLabel); 1560 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1561 yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 1562 1563 XYToolTipGenerator toolTipGenerator = null; 1564 if (tooltips) { 1565 toolTipGenerator = new StandardXYToolTipGenerator(); 1566 } 1567 1568 XYURLGenerator urlGenerator = null; 1569 if (urls) { 1570 urlGenerator = new StandardXYURLGenerator(); 1571 } 1572 XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator, 1573 urlGenerator); 1574 1575 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1576 plot.setRenderer(renderer); 1577 plot.setOrientation(orientation); 1578 plot.setDomainCrosshairVisible(false); 1579 plot.setRangeCrosshairVisible(false); 1580 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1581 plot, legend); 1582 currentTheme.apply(chart); 1583 return chart; 1584 1585 } 1586 1587 /** 1588 * Creates a filled stepped XY plot with default settings. 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 * 1595 * @return A chart. 1596 */ 1597 public static JFreeChart createXYStepAreaChart(String title, 1598 String xAxisLabel, String yAxisLabel, XYDataset dataset) { 1599 return createXYStepAreaChart(title, xAxisLabel, yAxisLabel, dataset, 1600 PlotOrientation.VERTICAL, true, true, false); 1601 } 1602 1603 /** 1604 * Creates a filled stepped XY plot with default settings. 1605 * 1606 * @param title the chart title ({@code null} permitted). 1607 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1608 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1609 * @param dataset the dataset for the chart ({@code null} permitted). 1610 * @param orientation the plot orientation (horizontal or vertical) 1611 * ({@code null} NOT permitted). 1612 * @param legend a flag specifying whether or not a legend is required. 1613 * @param tooltips configure chart to generate tool tips? 1614 * @param urls configure chart to generate URLs? 1615 * 1616 * @return A chart. 1617 */ 1618 public static JFreeChart createXYStepAreaChart(String title, 1619 String xAxisLabel, String yAxisLabel, XYDataset dataset, 1620 PlotOrientation orientation, boolean legend, boolean tooltips, 1621 boolean urls) { 1622 1623 Args.nullNotPermitted(orientation, "orientation"); 1624 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1625 xAxis.setAutoRangeIncludesZero(false); 1626 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1627 1628 XYToolTipGenerator toolTipGenerator = null; 1629 if (tooltips) { 1630 toolTipGenerator = new StandardXYToolTipGenerator(); 1631 } 1632 1633 XYURLGenerator urlGenerator = null; 1634 if (urls) { 1635 urlGenerator = new StandardXYURLGenerator(); 1636 } 1637 XYItemRenderer renderer = new XYStepAreaRenderer( 1638 XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator, 1639 urlGenerator); 1640 1641 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1642 plot.setRenderer(renderer); 1643 plot.setOrientation(orientation); 1644 plot.setDomainCrosshairVisible(false); 1645 plot.setRangeCrosshairVisible(false); 1646 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1647 plot, legend); 1648 currentTheme.apply(chart); 1649 return chart; 1650 } 1651 1652 /** 1653 * Creates and returns a time series chart. A time series chart is an 1654 * {@link XYPlot} with a {@link DateAxis} for the x-axis and a 1655 * {@link NumberAxis} for the y-axis. The default renderer is an 1656 * {@link XYLineAndShapeRenderer}. 1657 * <P> 1658 * A convenient dataset to use with this chart is a 1659 * {@link org.jfree.data.time.TimeSeriesCollection}. 1660 * 1661 * @param title the chart title ({@code null} permitted). 1662 * @param timeAxisLabel a label for the time axis ({@code null} 1663 * permitted). 1664 * @param valueAxisLabel a label for the value axis ({@code null} 1665 * permitted). 1666 * @param dataset the dataset for the chart ({@code null} permitted). 1667 * 1668 * @return A time series chart. 1669 */ 1670 public static JFreeChart createTimeSeriesChart(String title, 1671 String timeAxisLabel, String valueAxisLabel, XYDataset dataset) { 1672 return createTimeSeriesChart(title, timeAxisLabel, valueAxisLabel, 1673 dataset, true, true, false); 1674 } 1675 1676 /** 1677 * Creates and returns a time series chart. A time series chart is an 1678 * {@link XYPlot} with a {@link DateAxis} for the x-axis and a 1679 * {@link NumberAxis} for the y-axis. The default renderer is an 1680 * {@link XYLineAndShapeRenderer}. 1681 * <P> 1682 * A convenient dataset to use with this chart is a 1683 * {@link org.jfree.data.time.TimeSeriesCollection}. 1684 * 1685 * @param title the chart title ({@code null} permitted). 1686 * @param timeAxisLabel a label for the time axis ({@code null} 1687 * permitted). 1688 * @param valueAxisLabel a label for the value axis ({@code null} 1689 * permitted). 1690 * @param dataset the dataset for the chart ({@code null} permitted). 1691 * @param legend a flag specifying whether or not a legend is required. 1692 * @param tooltips configure chart to generate tool tips? 1693 * @param urls configure chart to generate URLs? 1694 * 1695 * @return A time series chart. 1696 */ 1697 public static JFreeChart createTimeSeriesChart(String title, 1698 String timeAxisLabel, String valueAxisLabel, XYDataset dataset, 1699 boolean legend, boolean tooltips, boolean urls) { 1700 1701 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1702 timeAxis.setLowerMargin(0.02); // reduce the default margins 1703 timeAxis.setUpperMargin(0.02); 1704 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1705 valueAxis.setAutoRangeIncludesZero(false); // override default 1706 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); 1707 1708 XYToolTipGenerator toolTipGenerator = null; 1709 if (tooltips) { 1710 toolTipGenerator 1711 = StandardXYToolTipGenerator.getTimeSeriesInstance(); 1712 } 1713 1714 XYURLGenerator urlGenerator = null; 1715 if (urls) { 1716 urlGenerator = new StandardXYURLGenerator(); 1717 } 1718 1719 XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, 1720 false); 1721 renderer.setDefaultToolTipGenerator(toolTipGenerator); 1722 renderer.setURLGenerator(urlGenerator); 1723 plot.setRenderer(renderer); 1724 1725 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1726 plot, legend); 1727 currentTheme.apply(chart); 1728 return chart; 1729 1730 } 1731 1732 /** 1733 * Creates and returns a default instance of a candlesticks chart. 1734 * 1735 * @param title the chart title ({@code null} permitted). 1736 * @param timeAxisLabel a label for the time axis ({@code null} 1737 * permitted). 1738 * @param valueAxisLabel a label for the value axis ({@code null} 1739 * permitted). 1740 * @param dataset the dataset for the chart ({@code null} permitted). 1741 * @param legend a flag specifying whether or not a legend is required. 1742 * 1743 * @return A candlestick chart. 1744 */ 1745 public static JFreeChart createCandlestickChart(String title, 1746 String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, 1747 boolean legend) { 1748 1749 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1750 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1751 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); 1752 plot.setRenderer(new CandlestickRenderer()); 1753 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1754 plot, legend); 1755 currentTheme.apply(chart); 1756 return chart; 1757 1758 } 1759 1760 /** 1761 * Creates and returns a default instance of a high-low-open-close chart. 1762 * 1763 * @param title the chart title ({@code null} permitted). 1764 * @param timeAxisLabel a label for the time axis ({@code null} 1765 * permitted). 1766 * @param valueAxisLabel a label for the value axis ({@code null} 1767 * permitted). 1768 * @param dataset the dataset for the chart ({@code null} permitted). 1769 * @param legend a flag specifying whether or not a legend is required. 1770 * 1771 * @return A high-low-open-close chart. 1772 */ 1773 public static JFreeChart createHighLowChart(String title, 1774 String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, 1775 boolean legend) { 1776 1777 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1778 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1779 HighLowRenderer renderer = new HighLowRenderer(); 1780 renderer.setDefaultToolTipGenerator(new HighLowItemLabelGenerator()); 1781 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); 1782 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1783 plot, legend); 1784 currentTheme.apply(chart); 1785 return chart; 1786 1787 } 1788 1789 /** 1790 * Creates a bubble chart with default settings. The chart is composed of 1791 * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis, 1792 * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} 1793 * to draw the data items. 1794 * 1795 * @param title the chart title ({@code null} permitted). 1796 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1797 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1798 * @param dataset the dataset for the chart ({@code null} permitted). 1799 * 1800 * @return A bubble chart. 1801 */ 1802 public static JFreeChart createBubbleChart(String title, String xAxisLabel, 1803 String yAxisLabel, XYZDataset dataset) { 1804 return createBubbleChart(title, xAxisLabel, yAxisLabel, dataset, 1805 PlotOrientation.VERTICAL, true, true, false); 1806 } 1807 1808 /** 1809 * Creates a bubble chart with default settings. The chart is composed of 1810 * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis, 1811 * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} 1812 * to draw the data items. 1813 * 1814 * @param title the chart title ({@code null} permitted). 1815 * @param xAxisLabel a label for the X-axis ({@code null} permitted). 1816 * @param yAxisLabel a label for the Y-axis ({@code null} permitted). 1817 * @param dataset the dataset for the chart ({@code null} permitted). 1818 * @param orientation the orientation (horizontal or vertical) 1819 * ({@code null} NOT permitted). 1820 * @param legend a flag specifying whether or not a legend is required. 1821 * @param tooltips configure chart to generate tool tips? 1822 * @param urls configure chart to generate URLs? 1823 * 1824 * @return A bubble chart. 1825 */ 1826 public static JFreeChart createBubbleChart(String title, String xAxisLabel, 1827 String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, 1828 boolean legend, boolean tooltips, boolean urls) { 1829 1830 Args.nullNotPermitted(orientation, "orientation"); 1831 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1832 xAxis.setAutoRangeIncludesZero(false); 1833 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1834 yAxis.setAutoRangeIncludesZero(false); 1835 1836 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1837 1838 XYItemRenderer renderer = new XYBubbleRenderer( 1839 XYBubbleRenderer.SCALE_ON_RANGE_AXIS); 1840 if (tooltips) { 1841 renderer.setDefaultToolTipGenerator(new StandardXYZToolTipGenerator()); 1842 } 1843 if (urls) { 1844 renderer.setURLGenerator(new StandardXYZURLGenerator()); 1845 } 1846 plot.setRenderer(renderer); 1847 plot.setOrientation(orientation); 1848 1849 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1850 plot, legend); 1851 currentTheme.apply(chart); 1852 return chart; 1853 1854 } 1855 1856 /** 1857 * Creates a histogram chart. This chart is constructed with an 1858 * {@link XYPlot} using an {@link XYBarRenderer}. The domain and range 1859 * axes are {@link NumberAxis} instances. 1860 * 1861 * @param title the chart title ({@code null} permitted). 1862 * @param xAxisLabel the x axis label ({@code null} permitted). 1863 * @param yAxisLabel the y axis label ({@code null} permitted). 1864 * @param dataset the dataset ({@code null} permitted). 1865 * 1866 * @return A chart. 1867 */ 1868 public static JFreeChart createHistogram(String title, 1869 String xAxisLabel, String yAxisLabel, IntervalXYDataset dataset) { 1870 return createHistogram(title, xAxisLabel, yAxisLabel, dataset, 1871 PlotOrientation.VERTICAL, true, true, false); 1872 } 1873 1874 /** 1875 * Creates a histogram chart. This chart is constructed with an 1876 * {@link XYPlot} using an {@link XYBarRenderer}. The domain and range 1877 * axes are {@link NumberAxis} instances. 1878 * 1879 * @param title the chart title ({@code null} permitted). 1880 * @param xAxisLabel the x axis label ({@code null} permitted). 1881 * @param yAxisLabel the y axis label ({@code null} permitted). 1882 * @param dataset the dataset ({@code null} permitted). 1883 * @param orientation the orientation (horizontal or vertical) 1884 * ({@code null} NOT permitted). 1885 * @param legend create a legend? 1886 * @param tooltips display tooltips? 1887 * @param urls generate URLs? 1888 * 1889 * @return The chart. 1890 */ 1891 public static JFreeChart createHistogram(String title, 1892 String xAxisLabel, String yAxisLabel, IntervalXYDataset dataset, 1893 PlotOrientation orientation, boolean legend, boolean tooltips, 1894 boolean urls) { 1895 1896 Args.nullNotPermitted(orientation, "orientation"); 1897 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1898 xAxis.setAutoRangeIncludesZero(false); 1899 ValueAxis yAxis = new NumberAxis(yAxisLabel); 1900 1901 XYItemRenderer renderer = new XYBarRenderer(); 1902 if (tooltips) { 1903 renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator()); 1904 } 1905 if (urls) { 1906 renderer.setURLGenerator(new StandardXYURLGenerator()); 1907 } 1908 1909 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 1910 plot.setOrientation(orientation); 1911 plot.setDomainZeroBaselineVisible(true); 1912 plot.setRangeZeroBaselineVisible(true); 1913 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1914 plot, legend); 1915 currentTheme.apply(chart); 1916 return chart; 1917 1918 } 1919 1920 /** 1921 * Creates and returns a default instance of a box and whisker chart 1922 * based on data from a {@link BoxAndWhiskerCategoryDataset}. 1923 * 1924 * @param title the chart title ({@code null} permitted). 1925 * @param categoryAxisLabel a label for the category axis 1926 * ({@code null} permitted). 1927 * @param valueAxisLabel a label for the value axis ({@code null} 1928 * permitted). 1929 * @param dataset the dataset for the chart ({@code null} permitted). 1930 * @param legend a flag specifying whether or not a legend is required. 1931 * 1932 * @return A box and whisker chart. 1933 */ 1934 public static JFreeChart createBoxAndWhiskerChart(String title, 1935 String categoryAxisLabel, String valueAxisLabel, 1936 BoxAndWhiskerCategoryDataset dataset, boolean legend) { 1937 1938 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 1939 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1940 valueAxis.setAutoRangeIncludesZero(false); 1941 1942 BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); 1943 renderer.setDefaultToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); 1944 1945 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 1946 renderer); 1947 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1948 plot, legend); 1949 currentTheme.apply(chart); 1950 return chart; 1951 } 1952 1953 /** 1954 * Creates and returns a default instance of a box and whisker chart. 1955 * 1956 * @param title the chart title ({@code null} permitted). 1957 * @param timeAxisLabel a label for the time axis ({@code null} 1958 * permitted). 1959 * @param valueAxisLabel a label for the value axis ({@code null} 1960 * permitted). 1961 * @param dataset the dataset for the chart ({@code null} permitted). 1962 * @param legend a flag specifying whether or not a legend is required. 1963 * 1964 * @return A box and whisker chart. 1965 */ 1966 public static JFreeChart createBoxAndWhiskerChart(String title, 1967 String timeAxisLabel, String valueAxisLabel, 1968 BoxAndWhiskerXYDataset dataset, boolean legend) { 1969 1970 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1971 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1972 valueAxis.setAutoRangeIncludesZero(false); 1973 XYBoxAndWhiskerRenderer renderer = new XYBoxAndWhiskerRenderer(10.0); 1974 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); 1975 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1976 plot, legend); 1977 currentTheme.apply(chart); 1978 return chart; 1979 1980 } 1981 1982 /** 1983 * Creates a wind plot with default settings. 1984 * 1985 * @param title the chart title ({@code null} permitted). 1986 * @param xAxisLabel a label for the x-axis ({@code null} permitted). 1987 * @param yAxisLabel a label for the y-axis ({@code null} permitted). 1988 * @param dataset the dataset for the chart ({@code null} permitted). 1989 * @param legend a flag that controls whether or not a legend is created. 1990 * @param tooltips configure chart to generate tool tips? 1991 * @param urls configure chart to generate URLs? 1992 * 1993 * @return A wind plot. 1994 * 1995 */ 1996 public static JFreeChart createWindPlot(String title, String xAxisLabel, 1997 String yAxisLabel, WindDataset dataset, boolean legend, 1998 boolean tooltips, boolean urls) { 1999 2000 ValueAxis xAxis = new DateAxis(xAxisLabel); 2001 ValueAxis yAxis = new NumberAxis(yAxisLabel); 2002 yAxis.setRange(-12.0, 12.0); 2003 2004 WindItemRenderer renderer = new WindItemRenderer(); 2005 if (tooltips) { 2006 renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator()); 2007 } 2008 if (urls) { 2009 renderer.setURLGenerator(new StandardXYURLGenerator()); 2010 } 2011 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 2012 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 2013 plot, legend); 2014 currentTheme.apply(chart); 2015 return chart; 2016 2017 } 2018 2019 /** 2020 * Creates a wafer map chart. 2021 * 2022 * @param title the chart title ({@code null} permitted). 2023 * @param dataset the dataset ({@code null} permitted). 2024 * @param orientation the plot orientation (horizontal or vertical) 2025 * ({@code null} NOT permitted. 2026 * @param legend display a legend? 2027 * @param tooltips generate tooltips? 2028 * @param urls generate URLs? 2029 * 2030 * @return A wafer map chart. 2031 */ 2032 public static JFreeChart createWaferMapChart(String title, 2033 WaferMapDataset dataset, PlotOrientation orientation, 2034 boolean legend, boolean tooltips, boolean urls) { 2035 2036 Args.nullNotPermitted(orientation, "orientation"); 2037 WaferMapPlot plot = new WaferMapPlot(dataset); 2038 WaferMapRenderer renderer = new WaferMapRenderer(); 2039 plot.setRenderer(renderer); 2040 2041 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 2042 plot, legend); 2043 currentTheme.apply(chart); 2044 return chart; 2045 } 2046 2047}