Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Global function used by chart
CaptainBob
I have written the script below to programmatically change the tick colour on a chart to the same colour as the chart title's font. This is required because the use of different libraries with different background colours make the ticks hard to see, so I want to change these automatically to match a visible colour, such as that of the title.<br />
<br />
The script below works if added to each chart.<br />
<br />
However, I don't want to manually add it to each of the 50 charts for code maintenance reasons. It makes more sense to re-use a global function somewhere.<br />
<br />
I would like to add it once to a globally accessible location and pass the icsc through to that. <br />
> I tried putting it in a javascript file, but I get the error "+ ReferenceError: "setTickColour" is not defined. at line 3 of chart script:''". setTickColour is the function name in the js file.<br />
> I also tried adding it to the initialize section of the report, but this doesn't seem to change the tick colours, so either I'm not calling it properly or it doesn't work from there.<br />
<br />
The charts in the report set all inherit from a chart in the library, but because the titles are defined separately in each chart, the script is no longer inherited. <br />
<br />
Can anyone tell me how to solve this problem? Either some other way to inherit the chart script from a library, or use a javascript resource file or some other way.<br />
<br />
<br />
I'm using BIRT 2.3.1.<br />
<br />
<br />
function beforeRendering( gcs, icsc)<br />
{<br />
<br />
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);<br />
<br />
chart = icsc.getChartInstance();<br />
<br />
//Fetch the colours of the Title font<br />
tickColorRed = chart.getTitle().getLabel().getCaption().getColor().getRed();<br />
tickColorBlue = chart.getTitle().getLabel().getCaption().getColor().getBlue();<br />
tickColorGreen = chart.getTitle().getLabel().getCaption().getColor().getGreen();<br />
tickColorTransparency = chart.getTitle().getLabel().getCaption().getColor().getTransparency();<br />
<br />
//Determine the xAxis Primary Base axis and set the colour of the ticks to the colour determined above <br />
xAxis = chart.getBaseAxes()[0];<br />
xAxis.getMajorGrid().getTickAttributes().setColor( ColorDefinitionImpl.create(tickColorRed, tickColorGreen, tickColorBlue, tickColorTransparency) );<br />
<br />
//Determine how many Orthogonal axes there are<br />
axisCount = chart.getOrthogonalAxes(xAxis, true).length;<br />
<br />
//Set the colour of the ticks on each to the colour determined above<br />
for (i=0; i<axisCount; i++) {<br />
yAxis = chart.getOrthogonalAxes( xAxis, true)
;<br />
yAxis.getMajorGrid().getTickAttributes().setColor( ColorDefinitionImpl.create(tickColorRed, tickColorGreen, tickColorBlue, tickColorTransparency) );<br />
} <br />
}
Find more posts tagged with
Comments
mwilliams
Do you add the js file as a resource to your report in the property editor?
CaptainBob
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="75089" data-time="1301325846" data-date="28 March 2011 - 08:24 AM"><p>
Do you add the js file as a resource to your report in the property editor?<br /></p></blockquote>
<br />
Thanks.<br />
I got this to work by adding the resource to the report itself.<br />
<br />
<br />
If I add it to the library, the script file appears twice in the report resource list, but doesn't work.