Hi,

I have a requirement where I need to display multiple bars for the same event in a Gantt chart. I found some help from this link:-

http://www.java2s.com/Code/Java/Chart/JFreeChartGanttDemo2withmultiplebarspertask.htm

But, my case is that, the first set of events occur sequentially, and they are added to the Task Series as normal tasks. However, when the second set appears, I check for the existence of the event name in the task series. If yes, I add the second event to the first event as a subtask.

This approach is not working for me though. Any ideas????

Here is my code where I'm doing whats mentioned earlier...

**********************************************************
ArrayList eventNames = chartData.getEventNames();
ArrayList evnetStartDates = chartData.getEventStartDates();
ArrayList eventEndDates = chartData.getEventEndDates();
ArrayList eventStatus = chartData.getEventStatus();

//AppLogger.info("event names size in Plotter >>> "+eventNames.size());
for (int eCnt = 0; eCnt <eventNames.size(); eCnt++) {

String name = (String)eventNames.get(eCnt);
//AppLogger.info("event name >>> "+name);
Date date1 = (Date)evnetStartDates.get(eCnt);
Date date2 = (Date)eventEndDates.get(eCnt);
Double status = (Double) eventStatus.get(eCnt);

Task task = new Task(name, date1, date2);
task.setPercentComplete(status);

//if task already exists
if(ts.get(name)!=null)
{
    AppLogger.info(name+" already exists!! therefore adding as a subtask");
    ArrayList start_dates=new ArrayList();
    ArrayList end_dates=new ArrayList();
   
    //if no subtask,add the task's start and end dates to the list
    if(ts.get(name).getSubtaskCount()==0)
    {
        start_dates.add(ts.get(name).getDuration().getStart());
        end_dates.add(ts.get(name).getDuration().getEnd());
    }
    else
    {
        for(int i=0;i<ts.get(name).getSubtaskCount();i++)
        {
            Task subtask=ts.get(name).getSubtask(i);
            start_dates.add(subtask.getDuration().getStart());
            end_dates.add(subtask.getDuration().getEnd());
        }
    }
    //add the present task's start and end dates to the arraylists
    start_dates.add(date1);
    end_dates.add(date2);
   
    //sort the arraylists
    Collections.sort(start_dates);
    Collections.sort(end_dates);
   
    Date min_start_date=new Date();
    Date max_end_date=new Date();
   
    try
    {
        min_start_date=(Date)start_dates.get(0);
        max_end_date=(Date)end_dates.get(end_dates.size()-1);
    }
    catch(Exception e)
    {
        AppLogger.info("Date parse exception >>> "+e.toString());
    }
   
    AppLogger.info("min start_date for "+name+" >>> "+min_start_date);
    AppLogger.info("max end_date for "+name+" >>> "+max_end_date);
   
    //form new task
    Task temp=ts.get(name);
    ts.remove(temp);
   
    Task super_task=new Task(name,min_start_date,max_end_date);
    AppLogger.info("Created super task for "+name);
    for(int i=0;i<temp.getSubtaskCount();i++)
    {
        Task st=temp.getSubtask(i);
        super_task.addSubtask(st);
    }
    super_task.addSubtask(task);
    AppLogger.info("Added subtask(s) for "+name);
    ts.add(super_task);
    AppLogger.info("super task added to list.");
    //change the start and end dates of the supertask
    //ts.get(name).setDuration(new SimpleTimePeriod(min_start_date,max_end_date));
   
    //add the present subtask also to the super task
    //ts.get(name).addSubtask(task);
   
}
else
{
    AppLogger.info(name+" does not exist. therefore adding straight to task series");
    ts.add(task);
}

***********************************************************

ANY HELP IS HIGHLY HIGHLY HIGHLY APPRECIATED!!