Exemplo n.º 1
0
  private JFreeChart makeChart() throws KeyedException {

    if (chartSeries.size() == 0) throw new IllegalStateException("addChartSeries() not called");

    if (range == null) {
      for (ChartSeries s : chartSeries) {
        if (range == null) range = s.getTimeSeries().getRange();
        else range = range.union(s.getTimeSeries().getRange());
      }
    }

    // use number axis for dates, with special formatter
    DateAxis dateAxis = new DateAxis();
    dateAxis.setDateFormatOverride(new CustomDateFormat("M/d/y"));
    if (range.getTimeDomain().getLabel().equals("workweek"))
      dateAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());

    // combined plot with shared date axis
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(dateAxis);

    for (ChartSeries s : chartSeries) {
      makeSubPlot(plot, s);
    }

    // make the chart, remove the legend, set the title
    JFreeChart chart = new JFreeChart(plot);
    if (!withLegend) chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    chart.setTitle(new TextTitle(title));

    return chart;
  }