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)
Scripted area chart shading using embedded images
josephnina
Hi,
I am trying to script started area chart fills such that I get the desired pattern in the fill area for each type. Currently using the series palette, I do not ahve control over the pattern selected.
I am able to script the legend part correctly, but for some reason, the area fill on the chart doesnt work.
Here is the script.
==============================================
Before Factory Method
//Set green pattern as a persistant variable
var myimg =reportContext.getDesignHandle().getAllImages().get(0);
var tt = Base64.encodeBase64(myimg.getData());
var mydt = new String( tt, "UTF-8" );
reportContext.setPersistentGlobalVariable("greenPattern", mydt);
//Set Red Pattern as a persistent variable
var myimgr =reportContext.getDesignHandle().getAllImages().get(1);
var ttr = Base64.encodeBase64(myimgr.getData());
var mydtr = new String( ttr, "UTF-8" );
reportContext.setPersistentGlobalVariable("redPattern", mydtr);
//Set Grey Pattern as a persistent variable
var myimgg =reportContext.getDesignHandle().getAllImages().get(2);
var ttg = Base64.encodeBase64(myimgg.getData());
var mydtg = new String( ttg, "UTF-8" );
reportContext.setPersistentGlobalVariable("greyPattern", mydtg);
===============================================================
function beforeDrawLegendItem( lerh, bounds, icsc ) //This works!!!!!!!!!!!!!!!!!!!!
{
System.out.println("lerh.getLabel().getCaption().getValue():"+lerh.getLabel().getCaption().getValue());
var rc = icsc.getExternalContext().getScriptable();
if (lerh.getFill().getClass().isAssignableFrom(EmbeddedImageImpl)){ // PGVs set in beforeFactory
if (lerh.getLabel().getCaption().getValue() == "Goal Achieved"){
lerh.getFill().setData(rc.getPersistentGlobalVariable("greenPattern"));
}else if (lerh.getLabel().getCaption().getValue() == "Goal Not Achieved"){
lerh.getFill().setData(rc.getPersistentGlobalVariable("redPattern"));
}else {
lerh.getFill().setData(rc.getPersistentGlobalVariable("greyPattern"));
}
}
}
=======================================================
function beforeDrawDataPoint( dph, fill, icsc ) //Does not work!~!!!!!!! the if conditions are correct, but fill.setdata does not seem to have any effect
{
System.out.println("dph.getSeriesValue():"+dph.getSeriesValue());
System.out.println("dph.getBaseDisplayValue():"+dph.getBaseDisplayValue());
var rc = icsc.getExternalContext().getScriptable();
if (fill.getClass().isAssignableFrom(EmbeddedImageImpl)){ // PGVs set in beforeFactory
System.out.println("Inside if 1");
if (dph.getSeriesValue() == "Goal Achieved"){
System.out.println("Inside if ga");
fill.setData(rc.getPersistentGlobalVariable("greenPattern"));
}else if (dph.getSeriesValue() == "Goal Not Achieved"){
System.out.println("Inside if gna");
fill.setData(rc.getPersistentGlobalVariable("redPattern"));
}else {
System.out.println("Inside if others");
fill.setData(rc.getPersistentGlobalVariable("greyPattern"));
}
}
}
==========================================================
Attached are two images. One is the output without scripting, and another the progress so far.
Notice the area part, does not correctly have the pattern i need. Any advice ?
Thanks
Joseph
Find more posts tagged with
Comments
josephnina
btw, just found out that if I change the chart type to a Stacked Bar Chart, the coloring works as expected with no changes. It's with stacked area chart that this does not work.
Regards
Joseph
josephnina
Attached is a sample report that you can use to see the issue.
Switch between chart type as stacked bar vs stacked area to see the issue.
It also requires the classic auto database to work.
This is version 4 i think , but I need the implementation with 2.6.2.
Since the issue was also in 4, attaching that version.
Regards
Joseph