Gantt Chart: How to display task with a fixed width/height ?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
lionel
Posts: 6
Joined: Tue Mar 27, 2007 5:06 pm

Gantt Chart: How to display task with a fixed width/height ?

Post by lionel » Tue Mar 27, 2007 5:17 pm

Hi everybody,

I am new in JFreechart and currently I am facing the following problem:
Usually when drawing a gantt chart, all the tasks and subtasks are scaled to fit to the panel so that if there is only one task, it will take the whole panel place.
Is there a possibity to set a fixed width and height for tasks, so that (for example) resizing the window doesn't change the height/width used to draw tasks ? How can I do it ?

Any help will be appreciated.

Thans in advance.

Lionel

Demati
Posts: 12
Joined: Tue Jan 30, 2007 4:04 pm

Post by Demati » Tue Mar 27, 2007 6:22 pm

I was in a similar situation. I needed a fixed bar width on a Gantt chart. I went ahead and extended GanttRenderer with my own GantBarRenderer class. I overrode the calculateBarWidth() method and I was able to accomplish what I needed. I'm sure you could do something similar that would suit your needs.

lionel
Posts: 6
Joined: Tue Mar 27, 2007 5:06 pm

Good idea

Post by lionel » Tue Mar 27, 2007 9:09 pm

Thanks for your answer Demati. Now I know how to do to set the bar width myself.
The drawed bars are now centered in the display.
Do you know how I can tell the rendere to draw the bars beginning from the top of the screen (without centering them) ? many thanks in advance four your hints.

Demati
Posts: 12
Joined: Tue Jan 30, 2007 4:04 pm

Post by Demati » Wed Mar 28, 2007 3:22 pm

I don't know if I quite follow what you mean by "from the top of the screen", but you can control where on the range axis the bars are drawn, by setting the correct range values on the axis.

For example you could do the following:

Code: Select all

CategoryPlot plot = chart.getCategoryPlot();
ValueAxis axis = plot.getRangeAxis();
axis.setRangeWithMargins(time, time+30000.0);
This will give you a 30 second window (you can replace the number with something else for a larger or smaller value) view of your schedule, and will draw the first bar at the origin of the chart. Time in this case is the starting value of the dataset. It should help with scaling issues, but might not be exactly what you are looking for.

-George

lionel
Posts: 6
Joined: Tue Mar 27, 2007 5:06 pm

Post by lionel » Wed Mar 28, 2007 8:46 pm

Thanks again for your reply and sorry for my poor english :-)
I was actually searching for a simple way to set a fixed value for the category rows (category size) so that they are not calculated depending of the available screen area.

The only way I found is to write a CustomCategoryAxis class which and overwrite the calculateCategorySize method.

Have a nice evening

Locked