Home
Analytics
Positioning bars of Gantt Chart
cathyn
Hello,
I am working on a gantt chart (accessing a dataset with the following fields: projects ID, names, category, start date, end date and cost range). I want to group them (= display the bars with different color) according to the project cost but when I add this condition in Optional Y series Grouping, I am encountering some issues:
1. If I use project category in my Category (X) series, projects within the same category that have the different cost range overlap?
2. If I use project name in my Category (X) series, I don?t have any overlapping problem since all these project names are different but the some of the tasks labels don?t show up anymore if I place on the left of my y-axis?.
Thanks for the great example of gantt charts found on the forum and here is an image (see attachement) of the chart I get after running this report:
If we can go with this example and look at the 4 phases for IP: does anyone know what to do to display the bars of Phase 1? Phase 4 in stages instead of having them on the same line? I believe this should solve my problem.
Any help is appreciated.
Thanks,
Cathy
Find more posts tagged with
Comments
mwilliams
Hi Cathy,
Can you try attaching the image again? I don't see it. Or possibly recreate your issue with the sample database?
cathyn
Hello Michael,
I am actually referring to the example posted on the forum and here is the link.
http://www.birt-exchange.org/org/devshare/designing-birt-reports/200-gantt-chart-examples/
In this example, let?s consider the IP category: It has 4 phases displayed in-line. What I am looking for is how to display them in stages instead. The reason behind this is that if we have two phases with the same start date for example, they will overlap in this case and that is what I do not want.
Thanks for your help,
Cathy
mwilliams
So, you want them to look like they do in the second chart in the GanttExamples.rptdesign file? So they're on separate lines?
cathyn
Right! However, when you look at the X column in the dataset that is used for the 1st graph we have some X values that repeat and this is why we have that "sort" of grouping. But in the 2nd graph, they are all unique and that is way they are displayed that way. I basically want to keep the grouping but display them as shown in the 2nd graph.
Thanks,
-Cathy
mwilliams
Can you create this in a report using a flat file of data that will help depict your issue?
cathyn
I am not sure what you mean by that but this report accesses data from a flat file...
mwilliams
Can you create a CSV file with some sample data, fake or real, that you can make a sample report with to attach in here so that I can run it and see exactly the issue you're having and also be able to test with the report to help you get to where you want.
cathyn
Hello Michael,
I am attaching the report definition and the csv file with sample data. (I just save it as xls because the system could not let me upload the csv file).
Here is what I mainly want to accomplish.
1. Each project category on the left should be displayed only once
2. The bar color should depend on the cost of the project (I did this by using the ?Optional Y Series Grouping? function)
3. The issue is we can see for example that project 7 and 8 overlap (same for 9, 10 11) and I do not want this. I believe that this is happening because of the optional grouping I used because when projects have different cost, they are display in-line, not in stage as compared to projects (with same cost range) in Category1 for example.
Thanks,
-Cathy
mwilliams
Cathy,
Sorry about the delayed response. Does the attached report do what you're wanting to do?
cathyn
Hello Michael,
Thanks a lot! This is exactley what I wanted but I still have some issues: When I run the report with the sample data, it works perfectly but when I replace them with the actual data, the labels on the left are trucanted (maybe it is because they are quite longer than just "Category1") and there is a big space between the labels and the axis title. Would you please share what you did? Especially how did you get the labels on the left displayed only once?
Again, thank you so much for your help,
-Cathy
mwilliams
Cathy,
Sorry, look at the script in the chart's onRender method. Also, I changed your category value in your chart. Take a look at those two places, you'll see what I did. Let me know if you have questions.
cathyn
I see what is still causing me trouble: looking at the script, we have:
currentLabel = label.getCaption().getValue().substr(0,9);
The substr() method is the one that is truncating my labels and there is not a fixed value that I can use since the real category labels are not all of the same length...
Any other thought on this? Anyway, I think that we are really close and I think I can figure this out...
Again, I really appreciate all your help.
-Cathy
mwilliams
Cathy,
Ah, yeah, that worked for the example, you'd have to find a way to figure out how to set the length of the portion that you need. You could find this out outside the chart and pass it in through persistent global variables, possibly.
cathyn
See next post please...
cathyn
Hello Michael,
I had put this gantt chart on hold for some time but here I come again?
I am going to try to simplify my problem and hope that you will have a quick answer to this:
Note: The only reason I am using ?row [?Cost?] in the Optional Y Series grouping is to get different colors for my bars and that is based on the project cost.
Now here is my question: How can I use a script to specify the colors of the bars in this gantt chart (still depending on the project cost) while leaving this Optional Y Series grouping blank?
Here is my thought process but I am not sure about how the codes should look like:
//Maybe having something like this
function beforeDrawDataPoint( dph, fill, icsc )
{
var Cost = ??? // get value in the column ?Cost? of the DataSet that is being used for this chart
if (Cost == 1)
{ fill.set (148, 198, 222) }
else if (Cost == 2)
{ fill.set (., .., .. )}
etc
}
Thanks again for all your help,
-Cathy
mwilliams
Cathy,
I think this does what you're wanting. Take a look. It uses the CSV file you attached earlier.
richard_c
Hi Mike,
I had a look at your sample and understand how it works for a single series Gantt chart.
In my case, I have a two series gantt chart with the same sort of problem - i.e. the potential for horizontal bars from the second series overlapping ones in the first series.
Is there a way to vertically move or offset all of the first series bars (using script?) so that they are positioned slightly above the corresponding ones in the second series, i.e. so that if any overlap occurs then the bars from each series can still be clearly seen?
Alternatively do you have a workaround similar to your attached sample which would work for a two series Gantt chart?
Cheers,
Richard
mwilliams
Can you attach a report showing the issue? You should be able to adjust the y coordinate of the series data points in your chart script, in the beforeDrawSeries.
richard_c
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="114772" data-time="1362415004" data-date="04 March 2013 - 09:36 AM"><p>
Can you attach a report showing the issue? You should be able to adjust the y coordinate of the series data points in your chart script, in the beforeDrawSeries.<br /></p></blockquote>
<br />
Thanks for the tip Mike.<br />
<br />
I got it to work using the following:<br />
(note because I have a grouped series, I needed to use an ArrayList and store each series identifier as a work around to identify the first series from the second)<br />
<br />
importPackage(Packages.java.util);<br />
groupSeriesNamesAL = new ArrayList();<br />
isFirstSeries = true;<br />
<br />
function beforeDrawSeries( series, seriesRenderer, context ) {<br />
<br />
// This line doesn't worked on grouped series definitions: if( series.getSeriesIdentifier() == "Series 2" ){<br />
<br />
// Workaround:<br />
<br />
if(!groupSeriesNamesAL.contains(series.getSeriesIdentifier())) {<br />
isFirstSeries = true;<br />
} else {<br />
isFirstSeries = false;<br />
}<br />
<br />
if(seriesRenderer.getSeriesRenderingHints() != null) {<br />
var dpharray = seriesRenderer.getSeriesRenderingHints().getDataPoints();<br />
<br />
// Add the name of each series group<br />
groupSeriesNamesAL.add(series.getSeriesIdentifier());<br />
<br />
if(isFirstSeries) { <br />
// Move bars upward<br />
for(i=0; i < dpharray.length; i++) {<br />
yval = dpharray
.getLocation().getY();<br />
dpharray
.getLocation().setY(yval-5);<br />
}<br />
<br />
} else if(!isFirstSeries) {<br />
// Move bars downward<br />
for(i=0; i < dpharray.length; i++) {<br />
yval = dpharray
.getLocation().getY();<br />
dpharray
.getLocation().setY(yval+5);<br />
}<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
Cheers,<br />
<br />
Richard
mwilliams
You're welcome! Glad you got it! Let us know whenever you have questions!