示例#1
0
  /**
   * Creates a stacked vertical bar chart with default settings.
   *
   * @param title the chart title.
   * @param domainAxisLabel the label for the category axis.
   * @param rangeAxisLabel the label for the value axis.
   * @param data the dataset for the chart.
   * @param legend a flag specifying whether or not a legend is required.
   * @param tooltips configure chart to generate tool tips?
   * @param urls configure chart to generate URLs?
   * @return The chart.
   */
  public static JFreeChart createStackedBarChart(
      String title,
      java.awt.Font titleFont,
      String domainAxisLabel,
      String rangeAxisLabel,
      CategoryDataset data,
      PlotOrientation orientation,
      boolean legend,
      boolean tooltips,
      boolean urls,
      CategoryURLGenerator urlGenerator) {

    CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel);
    ValueAxis valueAxis = new NumberAxis(rangeAxisLabel);

    // create the renderer...
    StackedBarRenderer renderer = new StackedBarRenderer();
    if (tooltips) {
      renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
      renderer.setItemURLGenerator(urlGenerator);
    }

    CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;
  }