Home
Analytics
Text Wrapping of x axis labels and task labels in gantt chart
Kavita Rao
Hi All,
I am working on a Gantt chart using Birt 4.2 and facing few issues with the same.
I am using flat file data source and a csv file as my dataset.
I am mapping a row[Work] as X axis which contains a String of all category names and mapped a row[X]as task labels which contains the string of all Subcategories.
Now the length of these two text fields can be more than 100 characters.
I want to wrap these text labels.
I tried the following wrap function in the script:
function beforeDrawAxisLabel( axis, label, icsc )
{
var tst = label.getCaption().getValue();
var wrap = 15;
var repeat = Math.floor(tst.length() / wrap);
var str = tst;
if(repeat > 0)
{
str = "";
for(i = 0; i < repeat; i++)
{
str += tst.substring((i*wrap),((i+1)*wrap-1))+"\r\n";
}
if((tst.length() % wrap) > 0)
{
str += tst.substring((i*wrap-1),tst.length());
}
}
label.getCaption().setValue(str);
}
This is working for X axis labels not what needs to be done to wrap the task labels.
I even tried the following custom function:
CustomFunctions.TextWrap(dataSetRow["X"], 20)
but it returns blank or null values.
Even setting the property white space to normal or no wrapping does not make any effect.
The second issue is adding text labels to x axis and task label as "Category" and "Subcategory".
Can we add a static text field inside the chart area. Actually the report allows to add the text field above or below the chart area.
Another formatting issue is of Y axis scale.
As the task labels are long I just changed the Y axis scale to start from two years prior to the project.
Now the client wants that particular scale (of 2 years) which has no data to be invisible. That I need to hide the particular range of Y axis labels in gantt chart.
I have attached my csv file and design file for your reference.
Regards,
Kavita
Find more posts tagged with
Comments
kclark
Hi Kavita! Instead of having the string broken up in the chart script I created a computed column with a modified version of what you were using<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var tst = row["X"];
var wrap = 15;
var repeat = tst.length;
var str = tst;
if(repeat > 0)
{
str = "";
for(i = 0; i < repeat; i++)
{
str += tst.substring((i*wrap),((i+1)*wrap-1))+"\r\n";
}
if((tst.length % wrap) > 0)
{
str += tst.substring((i*wrap-1),tst.length);
}
}
this.value = str;</pre>
<br />
Then I opened the chart editor and instead of using row["x"] I clicked the expression editor > available column bindings > chart > edit bindings. Then I added my computed column here. Then I was able to use it as that value of the task label. Here's what it looks like now<br />
<br />
Kavita Rao
Hi Kclark,
Thanks for your reply.
This is what I exactly needed.
Now instead of a csv file I am using a scripted dataset which will fetch the values from my model and controller class.
Now when I created a new scripted dataset or any other type of dataset in its edit screen I do not have the computed column tab.
When I open the report provided by you I get the computed column tab.
Do you have any idea about why my dataset edit does not have a computed column tab? Or is there any other way create computed column?
Please find the attached screenshot of my dataset edit screen.
Regards,
Kavita