Example usage for org.jfree.data.gantt TaskSeriesCollection TaskSeriesCollection

List of usage examples for org.jfree.data.gantt TaskSeriesCollection TaskSeriesCollection

Introduction

In this page you can find the example usage for org.jfree.data.gantt TaskSeriesCollection TaskSeriesCollection.

Prototype

public TaskSeriesCollection() 

Source Link

Document

Default constructor.

Usage

From source file:one.GanttDemo1.java

/**
 * Creates a sample dataset for a Gantt chart.
 *
 * @return The dataset./*  ww w.ja  v  a2 s.com*/
 */
public static IntervalCategoryDataset createDataset() {

    final TaskSeries s1 = new TaskSeries("Scheduled");
    s1.add(new Task("Write Proposal",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
    s1.add(new Task("Obtain Approval",
            new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
    s1.add(new Task("Requirements Analysis",
            new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(5, Calendar.MAY, 2001))));
    s1.add(new Task("Design Phase",
            new SimpleTimePeriod(date(6, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001))));
    s1.add(new Task("Design Signoff",
            new SimpleTimePeriod(date(2, Calendar.JUNE, 2001), date(2, Calendar.JUNE, 2001))));
    s1.add(new Task("Alpha Implementation",
            new SimpleTimePeriod(date(3, Calendar.JUNE, 2001), date(31, Calendar.JULY, 2001))));
    s1.add(new Task("Design Review",
            new SimpleTimePeriod(date(1, Calendar.AUGUST, 2001), date(8, Calendar.AUGUST, 2001))));
    s1.add(new Task("Revised Design Signoff",
            new SimpleTimePeriod(date(10, Calendar.AUGUST, 2001), date(10, Calendar.AUGUST, 2001))));
    s1.add(new Task("Beta Implementation",
            new SimpleTimePeriod(date(12, Calendar.AUGUST, 2001), date(12, Calendar.SEPTEMBER, 2001))));
    s1.add(new Task("Testing",
            new SimpleTimePeriod(date(13, Calendar.SEPTEMBER, 2001), date(31, Calendar.OCTOBER, 2001))));
    s1.add(new Task("Final Implementation",
            new SimpleTimePeriod(date(1, Calendar.NOVEMBER, 2001), date(15, Calendar.NOVEMBER, 2001))));
    s1.add(new Task("Signoff",
            new SimpleTimePeriod(date(28, Calendar.NOVEMBER, 2001), date(30, Calendar.NOVEMBER, 2001))));
    s1.add(new Task("Database set up",
            new SimpleTimePeriod(date(15, Calendar.OCTOBER, 2001), date(30, Calendar.OCTOBER, 2001))));

    final TaskSeries s2 = new TaskSeries("Actual");
    s2.add(new Task("Write Proposal",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
    s2.add(new Task("Obtain Approval",
            new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
    s2.add(new Task("Requirements Analysis",
            new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(15, Calendar.MAY, 2001))));
    s2.add(new Task("Design Phase",
            new SimpleTimePeriod(date(15, Calendar.MAY, 2001), date(17, Calendar.JUNE, 2001))));
    s2.add(new Task("Design Signoff",
            new SimpleTimePeriod(date(30, Calendar.JUNE, 2001), date(30, Calendar.JUNE, 2001))));
    s2.add(new Task("Alpha Implementation",
            new SimpleTimePeriod(date(1, Calendar.JULY, 2001), date(12, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Design Review",
            new SimpleTimePeriod(date(12, Calendar.SEPTEMBER, 2001), date(22, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Revised Design Signoff",
            new SimpleTimePeriod(date(25, Calendar.SEPTEMBER, 2001), date(27, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Beta Implementation",
            new SimpleTimePeriod(date(27, Calendar.SEPTEMBER, 2001), date(30, Calendar.OCTOBER, 2001))));
    s2.add(new Task("Testing",
            new SimpleTimePeriod(date(31, Calendar.OCTOBER, 2001), date(17, Calendar.NOVEMBER, 2001))));
    s2.add(new Task("Final Implementation",
            new SimpleTimePeriod(date(18, Calendar.NOVEMBER, 2001), date(5, Calendar.DECEMBER, 2001))));
    s2.add(new Task("Signoff",
            new SimpleTimePeriod(date(10, Calendar.DECEMBER, 2001), date(11, Calendar.DECEMBER, 2001))));

    final TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(s1);
    collection.add(s2);

    return collection;
}

From source file:org.matsim.contrib.dvrp.util.chart.ScheduleCharts.java

private static TaskSeriesCollection createScheduleDataset(Collection<? extends Vehicle> vehicles,
        DescriptionCreator descriptionCreator) {
    TaskSeriesCollection collection = new TaskSeriesCollection();

    for (Vehicle v : vehicles) {
        Schedule schedule = v.getSchedule();

        final TaskSeries scheduleTaskSeries = new TaskSeries(v.getId().toString());

        if (schedule.getStatus() == ScheduleStatus.UNPLANNED) {
            collection.add(scheduleTaskSeries);
            continue;
        }//from   w w w.ja v a 2s  . c  om

        for (Task t : schedule.getTasks()) {
            String description = descriptionCreator.create(t);

            TimePeriod duration = new SimpleTimePeriod(//
                    new Date((int) Math.floor(t.getBeginTime() * 1000)), //
                    new Date((int) Math.ceil(t.getEndTime() * 1000)));

            scheduleTaskSeries.add(new ChartTask(description, duration, t));
        }

        collection.add(scheduleTaskSeries);
    }

    return collection;
}

From source file:pisco.batch.visu.BatchingChartFactory.java

public static XYDataset createLatenessDataset(Batch[] batches) {
    final TaskSeriesCollection coll = new TaskSeriesCollection();
    for (int i = 0; i < batches.length; i++) {
        TaskSeries series = new TaskSeries(String.valueOf(i));
        final int dd = batches[i].getDueDate();
        final int compl = batches[i].getCompletionTime();
        TimePeriod p = dd < compl ? new SimpleTimePeriod(dd, compl) : new SimpleTimePeriod(compl, dd);
        series.add(new Task("B" + i, p));
        coll.add(series);//w  w w  . j a v  a2s .  c o  m
    }
    final XYTaskDataset dataset = new XYTaskDataset(coll);
    dataset.setTransposed(true);
    return dataset;

}

From source file:org.jfree.data.gantt.TaskSeriesCollectionTest.java

/**
 * Creates a sample collection for testing purposes.
 *
 * @return A sample collection./*from  ww  w. ja  v  a2 s .co  m*/
 */
private TaskSeriesCollection createCollection3() {

    // define subtasks
    Task sub1 = new Task("Sub1", new Date(11), new Date(111));
    Task sub2 = new Task("Sub2", new Date(22), new Date(222));
    Task sub3 = new Task("Sub3", new Date(33), new Date(333));
    Task sub4 = new Task("Sub4", new Date(44), new Date(444));
    Task sub5 = new Task("Sub5", new Date(55), new Date(555));
    Task sub6 = new Task("Sub6", new Date(66), new Date(666));
    sub1.setPercentComplete(0.111);
    sub2.setPercentComplete(0.222);
    sub3.setPercentComplete(0.333);
    sub4.setPercentComplete(0.444);
    sub5.setPercentComplete(0.555);
    sub6.setPercentComplete(0.666);

    TaskSeries seriesA = new TaskSeries("Series A");
    Task taskA1 = new Task("Task 1", new SimpleTimePeriod(new Date(100), new Date(200)));
    taskA1.setPercentComplete(0.1);
    taskA1.addSubtask(sub1);
    Task taskA2 = new Task("Task 2", new SimpleTimePeriod(new Date(220), new Date(350)));
    taskA2.setPercentComplete(0.2);
    taskA2.addSubtask(sub2);
    taskA2.addSubtask(sub3);
    seriesA.add(taskA1);
    seriesA.add(taskA2);

    TaskSeries seriesB = new TaskSeries("Series B");
    // note that we don't define taskB1
    Task taskB2 = new Task("Task 2", new SimpleTimePeriod(new Date(2220), new Date(3350)));
    taskB2.setPercentComplete(0.3);
    taskB2.addSubtask(sub4);
    taskB2.addSubtask(sub5);
    taskB2.addSubtask(sub6);
    seriesB.add(taskB2);

    TaskSeriesCollection tsc = new TaskSeriesCollection();
    tsc.add(seriesA);
    tsc.add(seriesB);

    return tsc;
}

From source file:Negocio.Produccion.Planificacion.GanttDemo.java

/**
 * Creates a sample dataset for a Gantt chart.
 *
 * @return The dataset.//from w ww  . j  av a  2 s .co  m
 */
public static IntervalCategoryDataset createDataset() {

    final TaskSeries s1 = new TaskSeries("Scheduled");
    s1.add(new Task("Write Proposal",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
    s1.add(new Task("Obtain Approval",
            new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
    s1.add(new Task("Requirements Analysis",
            new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(5, Calendar.MAY, 2001))));
    s1.add(new Task("Design Phase",
            new SimpleTimePeriod(date(6, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001))));
    s1.add(new Task("Design Signoff",
            new SimpleTimePeriod(date(2, Calendar.JUNE, 2001), date(2, Calendar.JUNE, 2001))));
    s1.add(new Task("Alpha Implementation",
            new SimpleTimePeriod(date(3, Calendar.JUNE, 2001), date(31, Calendar.JULY, 2001))));
    s1.add(new Task("Design Review",
            new SimpleTimePeriod(date(1, Calendar.AUGUST, 2001), date(8, Calendar.AUGUST, 2001))));
    s1.add(new Task("Revised Design Signoff",
            new SimpleTimePeriod(date(10, Calendar.AUGUST, 2001), date(10, Calendar.AUGUST, 2001))));
    s1.add(new Task("Beta Implementation",
            new SimpleTimePeriod(date(12, Calendar.AUGUST, 2001), date(12, Calendar.SEPTEMBER, 2001))));
    s1.add(new Task("Testing",
            new SimpleTimePeriod(date(13, Calendar.SEPTEMBER, 2001), date(31, Calendar.OCTOBER, 2001))));
    s1.add(new Task("Final Implementation",
            new SimpleTimePeriod(date(1, Calendar.NOVEMBER, 2001), date(15, Calendar.NOVEMBER, 2001))));
    s1.add(new Task("Signoff",
            new SimpleTimePeriod(date(28, Calendar.NOVEMBER, 2001), date(30, Calendar.NOVEMBER, 2001))));

    final TaskSeries s2 = new TaskSeries("Actual");
    s2.add(new Task("Write Proposal",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
    s2.add(new Task("Obtain Approval",
            new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
    s2.add(new Task("Requirements Analysis",
            new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(15, Calendar.MAY, 2001))));
    s2.add(new Task("Design Phase",
            new SimpleTimePeriod(date(15, Calendar.MAY, 2001), date(17, Calendar.JUNE, 2001))));
    s2.add(new Task("Design Signoff",
            new SimpleTimePeriod(date(30, Calendar.JUNE, 2001), date(30, Calendar.JUNE, 2001))));
    s2.add(new Task("Alpha Implementation",
            new SimpleTimePeriod(date(1, Calendar.JULY, 2001), date(12, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Design Review",
            new SimpleTimePeriod(date(12, Calendar.SEPTEMBER, 2001), date(22, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Revised Design Signoff",
            new SimpleTimePeriod(date(25, Calendar.SEPTEMBER, 2001), date(27, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Beta Implementation",
            new SimpleTimePeriod(date(27, Calendar.SEPTEMBER, 2001), date(30, Calendar.OCTOBER, 2001))));
    s2.add(new Task("Testing",
            new SimpleTimePeriod(date(31, Calendar.OCTOBER, 2001), date(17, Calendar.NOVEMBER, 2001))));
    s2.add(new Task("Final Implementation",
            new SimpleTimePeriod(date(18, Calendar.NOVEMBER, 2001), date(5, Calendar.DECEMBER, 2001))));
    s2.add(new Task("Signoff",
            new SimpleTimePeriod(date(10, Calendar.DECEMBER, 2001), date(11, Calendar.DECEMBER, 2001))));

    final TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(s1);
    collection.add(s2);

    return collection;
}

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java

private static XYTaskDataset getDrugDataSet(String demographic, String[] dins) {

    TaskSeriesCollection datasetDrug = new TaskSeriesCollection();
    oscar.oscarRx.data.RxPrescriptionData prescriptData = new oscar.oscarRx.data.RxPrescriptionData();

    for (String din : dins) {
        oscar.oscarRx.data.RxPrescriptionData.Prescription[] arr = prescriptData
                .getPrescriptionScriptsByPatientRegionalIdentifier(Integer.parseInt(demographic), din);
        TaskSeries ts = new TaskSeries(arr[0].getBrandName());
        for (oscar.oscarRx.data.RxPrescriptionData.Prescription pres : arr) {
            ts.add(new Task(pres.getBrandName(), pres.getRxDate(), pres.getEndDate()));
        }//from   w  w  w.  j  a va2 s . c  o  m
        datasetDrug.add(ts);
    }

    XYTaskDataset dataset = new XYTaskDataset(datasetDrug);
    dataset.setTransposed(true);
    dataset.setSeriesWidth(0.6);
    return dataset;
}

From source file:netmason.support.graphics.GanttDisplay.java

/**
 * Creates a sample dataset for a Gantt chart, using sub-tasks. In general,
 * you won't hard-code the dataset in this way - it's done here so that the
 * demo is self-contained.//from   w ww  . ja va2  s  .  c  o m
 * 
 * @return The dataset.
 */
private IntervalCategoryDataset createSampleDataset() {

    final Task t1 = new Task("Write Proposal", date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001));
    t1.setPercentComplete(1.00);
    s1.add(t1);

    final Task t2 = new Task("Obtain Approval", date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001));
    t2.setPercentComplete(1.00);
    s1.add(t2);

    // here is a task split into two subtasks...
    final Task t3 = new Task("Requirements Analysis", date(10, Calendar.APRIL, 2001),
            date(5, Calendar.MAY, 2001));
    final Task st31 = new Task("Requirements 1", date(10, Calendar.APRIL, 2001),
            date(25, Calendar.APRIL, 2001));
    st31.setPercentComplete(1.0);
    final Task st32 = new Task("Requirements 2", date(1, Calendar.MAY, 2001), date(5, Calendar.MAY, 2001));
    st32.setPercentComplete(1.0);
    t3.addSubtask(st31);
    t3.addSubtask(st32);
    s1.add(t3);

    // and another...
    final Task t4 = new Task("Design Phase", date(6, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001));
    final Task st41 = new Task("Design 1", date(6, Calendar.MAY, 2001), date(10, Calendar.MAY, 2001));
    st41.setPercentComplete(1.0);
    final Task st42 = new Task("Design 2", date(15, Calendar.MAY, 2001), date(20, Calendar.MAY, 2001));
    st42.setPercentComplete(1.0);
    final Task st43 = new Task("Design 3", date(23, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001));
    st43.setPercentComplete(0.50);
    t4.addSubtask(st41);
    t4.addSubtask(st42);
    t4.addSubtask(st43);
    s1.add(t4);

    final Task t5 = new Task("Design Signoff", date(2, Calendar.JUNE, 2001), date(2, Calendar.JUNE, 2001));
    s1.add(t5);

    final Task t6 = new Task("Alpha Implementation", date(3, Calendar.JUNE, 2001),
            date(31, Calendar.JULY, 2001));
    t6.setPercentComplete(0.60);

    s1.add(t6);

    final Task t7 = new Task("Design Review", date(1, Calendar.AUGUST, 2001), date(8, Calendar.AUGUST, 2001));
    t7.setPercentComplete(0.0);
    s1.add(t7);

    final Task t8 = new Task("Revised Design Signoff", date(10, Calendar.AUGUST, 2001),
            date(10, Calendar.AUGUST, 2001));
    t8.setPercentComplete(0.0);
    s1.add(t8);

    final Task t9 = new Task("Beta Implementation", date(12, Calendar.AUGUST, 2001),
            date(12, Calendar.SEPTEMBER, 2001));
    t9.setPercentComplete(0.0);
    s1.add(t9);

    final Task t10 = new Task("Testing", date(13, Calendar.SEPTEMBER, 2001), date(31, Calendar.OCTOBER, 2001));
    t10.setPercentComplete(0.0);
    s1.add(t10);

    final Task t11 = new Task("Final Implementation", date(1, Calendar.NOVEMBER, 2001),
            date(15, Calendar.NOVEMBER, 2001));
    t11.setPercentComplete(0.0);
    s1.add(t11);

    final Task t12 = new Task("Signoff", date(28, Calendar.NOVEMBER, 2001), date(30, Calendar.NOVEMBER, 2001));
    t12.setPercentComplete(0.0);
    s1.add(t12);

    final TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(s1);

    return collection;
}

From source file:org.jfree.chart.demo.GanttDemo2.java

/**
 * Creates a sample dataset for a Gantt chart, using sub-tasks.  In general, you won't 
 * hard-code the dataset in this way - it's done here so that the demo is self-contained.
 *
 * @return The dataset.// w w  w.  ja v  a 2 s  . co m
 */
private IntervalCategoryDataset createSampleDataset() {

    final TaskSeries s1 = new TaskSeries("Scheduled");

    final Task t1 = new Task("Write Proposal", date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001));
    t1.setPercentComplete(1.00);
    s1.add(t1);

    final Task t2 = new Task("Obtain Approval", date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001));
    t2.setPercentComplete(1.00);
    s1.add(t2);

    // here is a task split into two subtasks...
    final Task t3 = new Task("Requirements Analysis", date(10, Calendar.APRIL, 2001),
            date(5, Calendar.MAY, 2001));
    final Task st31 = new Task("Requirements 1", date(10, Calendar.APRIL, 2001),
            date(25, Calendar.APRIL, 2001));
    st31.setPercentComplete(1.0);
    final Task st32 = new Task("Requirements 2", date(1, Calendar.MAY, 2001), date(5, Calendar.MAY, 2001));
    st32.setPercentComplete(1.0);
    t3.addSubtask(st31);
    t3.addSubtask(st32);
    s1.add(t3);

    // and another...
    final Task t4 = new Task("Design Phase", date(6, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001));
    final Task st41 = new Task("Design 1", date(6, Calendar.MAY, 2001), date(10, Calendar.MAY, 2001));
    st41.setPercentComplete(1.0);
    final Task st42 = new Task("Design 2", date(15, Calendar.MAY, 2001), date(20, Calendar.MAY, 2001));
    st42.setPercentComplete(1.0);
    final Task st43 = new Task("Design 3", date(23, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001));
    st43.setPercentComplete(0.50);
    t4.addSubtask(st41);
    t4.addSubtask(st42);
    t4.addSubtask(st43);
    s1.add(t4);

    final Task t5 = new Task("Design Signoff", date(2, Calendar.JUNE, 2001), date(2, Calendar.JUNE, 2001));
    s1.add(t5);

    final Task t6 = new Task("Alpha Implementation", date(3, Calendar.JUNE, 2001),
            date(31, Calendar.JULY, 2001));
    t6.setPercentComplete(0.60);

    s1.add(t6);

    final Task t7 = new Task("Design Review", date(1, Calendar.AUGUST, 2001), date(8, Calendar.AUGUST, 2001));
    t7.setPercentComplete(0.0);
    s1.add(t7);

    final Task t8 = new Task("Revised Design Signoff", date(10, Calendar.AUGUST, 2001),
            date(10, Calendar.AUGUST, 2001));
    t8.setPercentComplete(0.0);
    s1.add(t8);

    final Task t9 = new Task("Beta Implementation", date(12, Calendar.AUGUST, 2001),
            date(12, Calendar.SEPTEMBER, 2001));
    t9.setPercentComplete(0.0);
    s1.add(t9);

    final Task t10 = new Task("Testing", date(13, Calendar.SEPTEMBER, 2001), date(31, Calendar.OCTOBER, 2001));
    t10.setPercentComplete(0.0);
    s1.add(t10);

    final Task t11 = new Task("Final Implementation", date(1, Calendar.NOVEMBER, 2001),
            date(15, Calendar.NOVEMBER, 2001));
    t11.setPercentComplete(0.0);
    s1.add(t11);

    final Task t12 = new Task("Signoff", date(28, Calendar.NOVEMBER, 2001), date(30, Calendar.NOVEMBER, 2001));
    t12.setPercentComplete(0.0);
    s1.add(t12);

    final TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(s1);

    return collection;
}

From source file:com.opendoorlogistics.components.gantt.GanttChartComponent.java

@Override
public void execute(final ComponentExecutionApi api, int mode, Object configuration,
        ODLDatastore<? extends ODLTable> ioDs, ODLDatastoreAlterable<? extends ODLTableAlterable> outputDs) {
    // Get items and sort by resource then date
    final StringConventions sc = api.getApi().stringConventions();
    List<GanttItem> items = GanttItem.beanMapping.getTableMapping(0).readObjectsFromTable(ioDs.getTableAt(0));

    // Rounding doubles to longs can create small errors where a start time is 1 millisecond after an end.
    // Set all start times to be <= end time
    for (GanttItem item : items) {
        if (item.getStart() == null || item.getEnd() == null) {
            throw new RuntimeException("Found Gannt item with null start or end time.");
        }/* w  ww. ja  v  a2  s  .com*/

        if (item.getStart().getValue() > item.getEnd().getValue()) {
            item.setStart(item.getEnd());
        }
    }

    Collections.sort(items, new Comparator<GanttItem>() {

        @Override
        public int compare(GanttItem o1, GanttItem o2) {
            int diff = sc.compareStandardised(o1.getResourceId(), o2.getResourceId());
            if (diff == 0) {
                diff = o1.getStart().compareTo(o2.getStart());
            }
            if (diff == 0) {
                diff = o1.getEnd().compareTo(o2.getEnd());
            }
            if (diff == 0) {
                diff = sc.compareStandardised(o1.getActivityId(), o2.getActivityId());
            }
            if (diff == 0) {
                diff = Colours.compare(o1.getColor(), o2.getColor());
            }
            return diff;
        }
    });

    // Filter any zero duration items
    Iterator<GanttItem> it = items.iterator();
    while (it.hasNext()) {
        GanttItem item = it.next();
        if (item.getStart().compareTo(item.getEnd()) == 0) {
            it.remove();
        }
    }

    // Get average colour for each activity type
    Map<String, CalculateAverageColour> calcColourMap = api.getApi().stringConventions()
            .createStandardisedMap();
    for (GanttItem item : items) {
        CalculateAverageColour calc = calcColourMap.get(item.getActivityId());
        if (calc == null) {
            calc = new CalculateAverageColour();
            calcColourMap.put(item.getActivityId(), calc);
        }
        calc.add(item.getColor());
    }

    // Put into colour map
    Map<String, Color> colourMap = api.getApi().stringConventions().createStandardisedMap();
    for (Map.Entry<String, CalculateAverageColour> entry : calcColourMap.entrySet()) {
        colourMap.put(entry.getKey(), entry.getValue().getAverage());
    }

    // Split items by resource
    ArrayList<ArrayList<GanttItem>> splitByResource = new ArrayList<>();
    ArrayList<GanttItem> current = null;
    for (GanttItem item : items) {
        if (current == null
                || sc.compareStandardised(current.get(0).getResourceId(), item.getResourceId()) != 0) {
            current = new ArrayList<>();
            splitByResource.add(current);
        }
        current.add(item);
    }

    // put into jfreechart's task data structure
    TaskSeries ts = new TaskSeries("Resources");
    for (ArrayList<GanttItem> resource : splitByResource) {
        // get earliest and latest time (last time may not be in the last item)
        ODLTime earliest = resource.get(0).getStart();
        ODLTime latest = null;
        for (GanttItem item : resource) {
            if (latest == null || latest.compareTo(item.getEnd()) < 0) {
                latest = item.getEnd();
            }
        }

        Task task = new Task(resource.get(0).getResourceId(), new Date(earliest.getTotalMilliseconds()),
                new Date(latest.getTotalMilliseconds()));

        // add all items as subtasks
        for (GanttItem item : resource) {
            task.addSubtask(new MySubtask(item, new Date(item.getStart().getTotalMilliseconds()),
                    new Date(item.getEnd().getTotalMilliseconds())));
        }

        ts.add(task);
    }
    TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(ts);

    // Create the plot
    CategoryAxis categoryAxis = new CategoryAxis(null);
    DateAxis dateAxis = new DateAxis("Time");
    CategoryItemRenderer renderer = new MyRenderer(collection, colourMap);
    final CategoryPlot plot = new CategoryPlot(collection, categoryAxis, dateAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.getDomainAxis().setLabel(null);

    ((DateAxis) plot.getRangeAxis()).setDateFormatOverride(new DateFormat() {

        @Override
        public Date parse(String source, ParsePosition pos) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
            toAppendTo.append(new ODLTime(date.getTime()).toString());
            return toAppendTo;
        }
    });

    // Create the chart and apply the standard theme without shadows to it
    api.submitControlLauncher(new ControlLauncherCallback() {

        @Override
        public void launchControls(ComponentControlLauncherApi launcherApi) {
            JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
            StandardChartTheme theme = new StandardChartTheme("standard theme", false);
            theme.setBarPainter(new StandardBarPainter());
            theme.apply(chart);

            class MyPanel extends ChartPanel implements Disposable {

                public MyPanel(JFreeChart chart) {
                    super(chart);
                }

                @Override
                public void dispose() {
                    // TODO Auto-generated method stub

                }

            }
            MyPanel chartPanel = new MyPanel(chart);
            launcherApi.registerPanel("Resource Gantt", null, chartPanel, true);
        }
    });

}

From source file:de.fhbingen.wbs.wpOverview.tabs.APCalendarPanel.java

/**
 * Convert work packages to tasks./*from ww w. ja  v  a2s .  c o m*/
 * @param userWp
 *            list with work packages.
 * @return IntervalCategoryDataset: tasks of the work packages.
 */
public final IntervalCategoryDataset createDataset(final List<Workpackage> userWp) {

    final TaskSeries s1 = new TaskSeries(LocalizedStrings.getGeneralStrings().overview());
    colorList = new ArrayList<Integer>();
    for (Workpackage actualPackage : userWp) {
        if (actualPackage.getEndDateCalc() != null && actualPackage.getStartDateCalc() != null) {
            if (actualPackage.getlastRelevantIndex() <= showLevels) {

                Date endDateCalc = null;
                Date start = null;

                endDateCalc = actualPackage.getEndDateCalc();
                start = actualPackage.getStartDateCalc();

                String indent = "";

                for (int i = 0; i < actualPackage.getlastRelevantIndex(); i++) {
                    indent += "   ";
                }
                if (!endDateCalc.before(start)) {
                    Task t = new Task(indent + actualPackage.toString(),
                            new SimpleTimePeriod(start, endDateCalc));
                    t.setPercentComplete(0.01 * WpManager.calcPercentComplete(actualPackage.getBac(),
                            actualPackage.getEtc(), actualPackage.getAc()));
                    s1.add(t);
                    colorList.add(actualPackage.getlastRelevantIndex());
                }

            }
        }
    }

    final TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(s1);

    return collection;
}