Ejemplo n.º 1
0
  /**
   * Creates an area chart with default settings.
   *
   * @param title the chart title.
   * @param categoryAxisLabel the label for the category axis.
   * @param valueAxisLabel 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 an area chart.
   */
  public static JFreeChart createAreaChart(
      String title,
      java.awt.Font titleFont,
      String categoryAxisLabel,
      String valueAxisLabel,
      CategoryDataset data,
      PlotOrientation orientation,
      boolean legend,
      boolean tooltips,
      boolean urls,
      CategoryURLGenerator urlGenerator) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    categoryAxis.setCategoryMargin(0.0);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
    AreaRenderer renderer = new AreaRenderer();
    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;
  }
  private static void configureAreaRenderer(
      AreaRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) {
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    int seriesCount = valueSourceData.getSeriesCount();
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();

    // Loop all series and set series format.
    // Format based on dimension configs will be set later on in initFormatDelegate().
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
      renderer.setSeriesPaint(seriesIdx, seriesFormat.getAreaFillPaint());
    }
  }