Beispiel #1
0
  /**
   * Creates the JFreeChart data from the Gantt data
   *
   * @param gantt the input data
   */
  private IntervalCategoryDataset createDataset(Gantt gantt) {

    TaskSeries series = new TaskSeries("Scheduled");
    Map<String, Long> seriesDurations = new HashMap<String, Long>();

    for (String mapping : gantt.getMappings()) {
      Task currenttask;

      currenttask = new Task(mapping, new SimpleTimePeriod(0, 1));
      series.add(currenttask);
      seriesDurations.put(mapping, 0l);
    }

    for (GanttElement element : gantt.getElementSet()) {
      Task t =
          new Task(element.getTitle(), new SimpleTimePeriod(element.getStart(), element.getEnd()));
      series.get(element.getMapping()).addSubtask(t);

      long currentSerieDuration = seriesDurations.get(element.getMapping());
      seriesDurations.put(element.getMapping(), Math.max(currentSerieDuration, element.getEnd()));
    }

    for (String mapping : seriesDurations.keySet()) {
      series.get(mapping).setDuration(new SimpleTimePeriod(0, seriesDurations.get(mapping)));
    }

    TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(series);

    return collection;
  }
Beispiel #2
0
  /**
   * Creates a chart.
   *
   * @param dataset a dataset.
   * @return A chart.
   */
  private JFreeChart createChart(Gantt gantt, IntervalCategoryDataset dataset) {

    JFreeChart chart =
        ChartFactory.createGanttChart(
            "Solution Gantt", // title
            "Operators", // x-axis label
            "Time", // y-axis label
            null, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
            );

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    Paint p = getBackgroundColorGradient();
    chart.setBackgroundPaint(p);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setOrientation(PlotOrientation.HORIZONTAL);

    DateAxis xaxis = (DateAxis) plot.getRangeAxis();
    xaxis.setDateFormatOverride(new VertexDateFormat());
    xaxis.setPositiveArrowVisible(true);

    DefaultDrawingSupplier d = new DefaultDrawingSupplier();

    plot.setDrawingSupplier(d);
    GanttRenderer ren = new MyGanttRenderer();

    for (GanttElement element : gantt.getElementSet()) {
      ((MyGanttRenderer) ren).addColor(element.getTitle(), element.getColor());
    }

    ren.setSeriesItemLabelsVisible(0, false);
    ren.setSeriesVisibleInLegend(0, false);
    ren.setSeriesItemLabelGenerator(0, new IntervalCategoryItemLabelGenerator());
    ren.setSeriesToolTipGenerator(0, new MapperGanttToolTipGenerator());

    ren.setAutoPopulateSeriesShape(false);

    plot.setRenderer(ren);

    plot.setDataset(dataset);
    return chart;
  }