Gantt Chart Issue

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
zulfikaralib
Posts: 14
Joined: Thu Sep 22, 2005 5:38 am
Location: Mumbai, India
Contact:

Gantt Chart Issue

Post by zulfikaralib » Mon Jul 03, 2006 8:03 am

Hi David,

I am drawing a Gantt Chart using JFreeChart. The following is the data that I am fetching from the database:
ACTID NAME PLNSTRTDATE PLNENDDATE ACTSTRTDATE ACTENDDATE
5 Approve PMP 5/1/2006 6/30/2006 5/1/2006 5/1/2006
140 Check in/Check out 5/1/2006 6/30/2006 5/1/2006 5/1/2006
139 Doc Preparation 5/1/2006 6/30/2006 5/1/2006 5/1/2006
103 HW/SW 5/1/2006 6/30/2006 5/1/2006 5/1/2006
6 Baseline PMP 6/1/2006 6/21/2006 6/1/2006 6/1/2006
1 Project Kick off 6/6/2006 6/28/2006 6/6/2006 6/6/2006
8 Project Doc Prep 6/7/2006 7/31/2006 6/1/2006 6/26/2006
105 Review Prj Est 6/12/2006 6/16/2006 6/12/2006 6/12/2006
140 Check in/Check out 6/20/2006 6/29/2006 6/20/2006 6/20/2006

The following is the code that I use to generate the Gantt:

Code: Select all

IntervalCategoryDataset intervalcategorydataset;
Iterator iter = ganttchart.listIterator();
TaskSeries scheduled = new TaskSeries("Scheduled");
TaskSeries actual = new TaskSeries("Actual");
TaskSeriesCollection taskseriescollection = new TaskSeriesCollection();

while (iter.hasNext())
{
     prjVO = (ProjectVO)iter.next();
     scheduled.add(new Task(prjVO.getName(),prjVO.getPSdate(),prjVO.getPEdate()));
     actual.add(new Task(prjVO.getName(),prjVO.getASdate(),prjVO.getAEdate()));
}
				
taskseriescollection.add(scheduled);
taskseriescollection.add(actual);
intervalcategorydataset=taskseriescollection;
                
JFreeChart jfreechart = ChartFactory.createGanttChart("Gantt Chart", "Task", "Date", intervalcategorydataset, true, true, false);
CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
//categoryplot.getDomainAxis().setCategoryMargin(10);
GanttRenderer renderer = (GanttRenderer)categoryplot.getRenderer(0); 
renderer.setMaxBarWidth(0.05);
renderer.setItemMargin(0.1);
renderer.setSeriesPaint(0, Color.green);
//categoryplot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10F);
                
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(jfreechart, 1000, height, info, session);
session.setAttribute("aim/filename",filename);
                
ChartUtilities.writeImageMap(pw, filename, info);
pw.flush();
The problem here is that the Gantt is being generated but it is not displaying the last Activity! Could you please explain me the reason.

The following is the query that I use to fetch the records:

Code: Select all

select distinct a.Activity_id, b.Name, a.plan_start_date, a.plan_end_date, 
NVL(a.act_start_date, a.plan_start_date) ACT_START_DATE, 
NVL(a.act_end_date, NVL(a.act_start_date,a.plan_start_date)) ACT_END_DATE 
from Taim_Allocated_task a, Taim_Activity b 
where a.task_id in 
	  (select task_id from taim_task 
	   where Project_id='TD0001'
	   and company_id='794') 
and a.company_id='794'
and b.Company_id = a.company_id
and b.activity_id= a.activity_id
and a.status='Y'
order by a.plan_start_date
Is there any way that we can get the last record punched in the Gantt?

Please do reply to this post ASAP as we have to move our code into production by Wednesday, 5th July 2006.
Zulfikarali Barodawala

zulfikaralib
Posts: 14
Joined: Thu Sep 22, 2005 5:38 am
Location: Mumbai, India
Contact:

Post by zulfikaralib » Mon Jul 03, 2006 10:00 am

Put this in another way, is there any way of getting two Activities with the same name on the chart?

Please do reply ASAP please.
Zulfikarali Barodawala

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Mon Jul 03, 2006 10:53 am

The task keys do need to be unique, but you can use a trick to display the same string for different keys (at the risk of confusing the people reading the chart). Just note that the label comes from the toString() method, and that the key can be any instance of Comparable. The String class is a convenient one to use for the task keys, but you could create a new class TaskKey that holds two fields:

int id;
String displayLabel;

Then implement Comparable to check the id field, but have toString() return the displayLabel. Then there is no need for the displayLabel to be unique, because the id is used to differentiate the keys.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

zulfikaralib
Posts: 14
Joined: Thu Sep 22, 2005 5:38 am
Location: Mumbai, India
Contact:

Post by zulfikaralib » Mon Jul 03, 2006 1:38 pm

I had just given the Activity Id for your reference. I need something like this:

Activity 1 XXX----------

Activity 2 XXXXXXXXXX-----

Activity 3 XXXXXXXXXXXXXX---

Activity 1 XXXXXXXXXXXXX---------------

I am not getting this, in my case the last Activity, i.e. Activity 1 gets missed out completely.

And also if the 2 activities with the same name exists one after another, the planned and actual dates of the 2nd activity gets assigned to the 3rd Activity.
e.g. Data:
Activity Name Planned Start Date Planned End Date
Activity 1 2006/06/12 2006/06/15
Activity 1 2006/07/03 2006/07/06
Activity 2 2006/06/13 2006/06/14

The gantt looks like this:
AAAAAAAAAAAA01 JuneAAAA15 JuneAAAA30 JuneAAAA15 July
Activity 1 AAAAAAAAAAAA---(12/06 - 15/06)
Activity 3 aaaaaaaaaaaaaaaaaaaaaaaaaaaaa--(03/07 - 06-07)

What is the reason behind this? Please explain and suggest changes to the code.
Zulfikarali Barodawala

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Mon Jul 03, 2006 3:57 pm

Perhaps you should distil your code into a small runnable demo and post that.

As I said, though, the task keys are required to be unique. Adding a second task with the same key as one that already exists will overwrite the existing task.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked