Home
Analytics
changing bar colors in ganntt chart via script
jsOpa
Hi guys,<br />
<br />
I have a small problem. I want to change the color of a bar in a gantt chart via script. I found a lot of examples for this, and I also created some reports with this scripting in the past, and they are working well.<br />
<br />
But my newest report don't want to change the color.<br />
I use the following code (it is not the whole code but the rest of the functions are working well):<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>importPackage(Packages.org.eclipse.birt.chart.event);
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
importPackage(Packages.org.eclipse.birt.chart.util);
function beforeDrawDataPoint( dph, fill, icsc )
{
var titel=dph.getOrthogonalDisplayValue();
titel=titel.substr(-1); //I only need the last character of the label
// This part I use to check the values I need as parameters
importPackage( Packages.java.io );
out = new PrintWriter( new FileWriter( "C:/birt_test.txt", true ) );
//out.println( "dph base"+dph.getBaseDisplayValue());
out.println( "dph display: " + dph.getOrthogonalDisplayValue());
out.println( "titel: " + titel);
//out.println( "dph series"+dph.getSeriesDisplayValue());
out.close();
if (titel == 'U') {fill.set(0,0,255);}
if (titel == 'S') {fill.set(0,255,0);}
if (titel == 'F') {fill.set(255,0,0);}
}</pre>
<br />
Imho it should work, I use the same code in other gantt chart reports, but it doesn't. I also get no error message so it looks like the code is ok.<br />
<br />
Do you have any idea?<br />
<br />
Thanks in advance,<br />
<br />
J?rg<br />
<br />
PS: I'm using Birt Report Designer 2.5.0.
Find more posts tagged with
Comments
mcremer
<blockquote class='ipsBlockquote' data-author="'jsOpa'" data-cid="83103" data-time="1316606040" data-date="21 September 2011 - 04:54 AM"><p>
Hi guys,<br />
<br />
I have a small problem. I want to change the color of a bar in a gantt chart via script. I found a lot of examples for this, and I also created some reports with this scripting in the past, and they are working well.<br />
<br />
But my newest report don't want to change the color.<br />
I use the following code (it is not the whole code but the rest of the functions are working well):<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>importPackage(Packages.org.eclipse.birt.chart.event);
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
importPackage(Packages.org.eclipse.birt.chart.util);
function beforeDrawDataPoint( dph, fill, icsc )
{
var titel=dph.getOrthogonalDisplayValue();
titel=titel.substr(-1); //I only need the last character of the label
// This part I use to check the values I need as parameters
importPackage( Packages.java.io );
out = new PrintWriter( new FileWriter( "C:/birt_test.txt", true ) );
//out.println( "dph base"+dph.getBaseDisplayValue());
out.println( "dph display: " + dph.getOrthogonalDisplayValue());
out.println( "titel: " + titel);
//out.println( "dph series"+dph.getSeriesDisplayValue());
out.close();
if (titel == 'U') {fill.set(0,0,255);}
if (titel == 'S') {fill.set(0,255,0);}
if (titel == 'F') {fill.set(255,0,0);}
}</pre>
<br />
Imho it should work, I use the same code in other gantt chart reports, but it doesn't. I also get no error message so it looks like the code is ok.<br />
<br />
Do you have any idea?<br />
<br />
Thanks in advance,<br />
<br />
J?rg<br />
<br />
PS: I'm using Birt Report Designer 2.5.0.<br /></p></blockquote>
<br />
J?rg,<br />
<br />
In deed it looks like logicaly it should work. What do you see in the XML when you run it? And on what event did you run it? onRender?
jsOpa
Hi mcremer,<br />
<br />
I run the script in the "onRender" event.<br />
But what do you mean with <br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mcremer'" data-cid="83104" data-time="1316607242" data-date="21 September 2011 - 05:14 AM"><p>
... What do you see in the XML when you run it? ...<br /></p></blockquote>
<br />
Btw, thx for your fast reply
<br />
<br />
J?rg
mcremer
<blockquote class='ipsBlockquote' data-author="'jsOpa'" data-cid="83107" data-time="1316607810" data-date="21 September 2011 - 05:23 AM"><p>
Hi mcremer,<br />
<br />
I run the script in the "onRender" event.<br />
But what do you mean with <br /></p></blockquote>
If you run a report in a viewer. And look in the XML file you can see red markers were it went wrong (if it went wrong but worked). Hence me asking what do you see when you run the viewer from BIRT and thus giving you a bit more detail what went wrong.
jsOpa
Now you have lost me...
When I run the report in BIRT Report Designer then another window appears, and the report is displayed in this window. But there is no xml file...
The one and only xml file I can see is the xml source file. Where I can find "your" xml file?
Maybe the Problem is that I'm using the Birt RCP Report Designer.
jsOpa
Hi,<br />
<br />
next day next try...<br />
<br />
Now I installed the whole eclipse platform, and when I run the report including a debug report I get the following messages:<br />
<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
...
org.mozilla.javascript.EcmaError: ReferenceError: "MarkerLineImpl" is not defined. (/report/body/extended-item[
@id="
;135"]/method[
@name="
;onRender"]#26)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535)
at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3620)
at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1718)
...
</pre>
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
...
22.09.2011 12:46:26 org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor processExtendedContent
SCHWERWIEGEND: ReferenceError: "MarkerLineImpl" is not defined. at line 26 of chart script:''
org.eclipse.birt.chart.exception.ChartException: ReferenceError: "MarkerLineImpl" is not defined. at line 26 of chart script:''
at org.eclipse.birt.chart.script.ScriptHandler.convertException(ScriptHandler.java:1146)
at org.eclipse.birt.chart.script.ScriptHandler.callJavaScriptFunction(ScriptHandler.java:615)
at org.eclipse.birt.chart.script.ScriptHandler.callFunction(ScriptHandler.java:924)
...
</pre>
<br />
<br />
The funny thing is first, that this marker line which is scripted in the beforeGeneration function in onRender method, is shown at the right position, I use it as a marker for the current date. And second, MarkerLineImpl should be defined with the imported packages at the beginning of the code (see my first post in this thread).<br />
<br />
But nevertheless, I get no error message concerning the color setting of the bars according to the "titel" value.<br />
<br />
Does somebody has another idea to find out why the fill.set() commands are ignored?<br />
<br />
Thanks, J?rg