Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
how to set series color dynamically
sonic777
I would like to be able to dynamically specify the colors of the wedges in a bar chart.<br />
I have tried setting the wedge colors in a global variable; but, when the global variable is<br />
retrieved in the beforeDrawDataPoint routine the value of the global variable is null.<br />
<br />
How should the colors be set in script data set so that the values are retrievable in beforeDrawDataPoint?<br />
<br />
Adding debug logging reveals that when the beforeFactory routine is used, the initialize routine is being called twice.<br />
The second time initialize is called is after the fetch routine and appears to cause the values set by fetch to be deleted.<br />
<br />
<br />
**Sample<br />
*****Script Data Set *****<br />
** open **<br />
i = 0;<br />
sourcedata = new Array( new Array(4),<br />
new Array(4),<br />
new Array(4));<br />
sourcedata[0][0] = "2010-01-01";<br />
sourcedata[0][1] = "group1";<br />
sourcedata[0][2] = 45;<br />
<br />
sourcedata[1][0] = "2010-01-01";<br />
sourcedata[1][1] = "group2";<br />
sourcedata[1][2] = 20;<br />
<br />
sourcedata[2][0] = "2010-01-01";<br />
sourcedata[2][1] = "group3";<br />
sourcedata[2][2] = 25;<br />
globaldata=new Array( "group1","group2","group3");<br />
<br />
** fetch **<br />
if ( i < 3 ){<br />
row["date"] = sourcedata
[0];<br />
row["group"] = sourcedata
[1];<br />
row["cost"]= sourcedata
[2];<br />
i++;<br />
return true;<br />
}<br />
reportContext.setGlobalVariable("GROUP", globaldata );<br />
return false;<br />
<br />
*****Chart *****<br />
** onRender **<br />
function beforeDrawDataPoint( dph, fill, icsc ){<br />
var val =dph.getSeriesValue();<br />
grouplist=icsc.getExternalContext().getScriptable().getGlobalVariable("GROUP");<br />
if ( grouplist != undefined && grouplist != null ) {<br />
for(var j=0; j< grouplist.length; j++) {<br />
importPackage(Packages.java.io); <br />
fos = new java.io.FileOutputStream("c:\\temp.txt", true); <br />
printWriter = new java.io.PrintWriter(fos); <br />
printWriter.println( "val=" + val );<br />
printWriter.println( "grouplist[" + j+ "]=" + grouplist[j] );<br />
printWriter.close();<br />
if( val == grouplist[j] ){<br />
switch ( parseInt( j % 2 ) ){<br />
case 0:<br />
fill.set( 100,100,100 );<br />
break;<br />
case 1:<br />
fill.set( 200,200,200 );<br />
break;<br />
default:<br />
fill.set( 0,0,0 );<br />
break;<br />
}<br />
fill.setTransparency(127);<br />
} <br />
}<br />
} <br />
}
Find more posts tagged with
Comments
mwilliams
Have you tried using persistentGlobalVariables instead?
sonic777
hi
I have tried to use persistentGlobalVariables
but the global variable is not set
****
I set at fetch
reportContext.setPersistentGlobalVariable( "GROUP", globaldata );
and at onRender
grouplist=icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("GROUP");
mwilliams
So, the only issue is that the global variable comes in unset? If so, try putting a text control before your chart, bind it to your dataSet, and hide it using the visibility setting. This should make sure that the dataSet is ran prior to your chart running. Let me know.
sonic777
Hi Michael, <br />
i resolved the issue.<br />
i using "getHttpServletRequest"<br />
to dynamically specify the colors of bar chart.<br />
thank you.<br />
<br />
**Sample<br />
*****Script Data Set *****<br />
** open **<br />
i = 0;<br />
sourcedata = new Array( new Array(4),<br />
new Array(4),<br />
new Array(4));<br />
sourcedata[0][0] = "2010-01-01";<br />
sourcedata[0][1] = "group1";<br />
sourcedata[0][2] = 45;<br />
<br />
sourcedata[1][0] = "2010-01-01";<br />
sourcedata[1][1] = "group2";<br />
sourcedata[1][2] = 20;<br />
<br />
sourcedata[2][0] = "2010-01-01";<br />
sourcedata[2][1] = "group3";<br />
sourcedata[2][2] = 25;<br />
// globaldata=new Array( "group1","group2","group3");<br />
globaldata="group1,group2,group3";<br />
<br />
<br />
** fetch **<br />
if ( i < 3 ){<br />
row["date"] = sourcedata
[0];<br />
row["group"] = sourcedata
[1];<br />
row["cost"]= sourcedata
[2];<br />
i++;<br />
return true;<br />
}<br />
// reportContext.setGlobalVariable("GROUP", globaldata );<br />
reportContext.getHttpServletRequest().getSession().setAttribute("GROUP", globaldata);<br />
return false;<br />
<br />
*****Chart *****<br />
** onRender **<br />
function beforeDrawDataPoint( dph, fill, icsc ){<br />
var val =dph.getSeriesValue();<br />
//grouplist=icsc.getExternalContext().getScriptable().getGlobalVariable("GROUP");<br />
grouplisttmp=icsc.getExternalContext().getScriptable().getGlobalVariable("GROUP");<br />
<br />
// if ( grouplist != undefined && grouplist != null ) {<br />
if ( grouplisttmp != undefined && grouplisttmp != null ) {<br />
grouplisttmp=icsc.getExternalContext().getScriptable().getHttpServletRequest().getSession().getAttribute("GROUP");<br />
grouplist = grouplisttmp.split(",");<br />
<br />
for(var j=0; j< grouplist.length; j++) {<br />
importPackage(Packages.java.io); <br />
fos = new java.io.FileOutputStream("c:\\temp.txt", true); <br />
printWriter = new java.io.PrintWriter(fos); <br />
printWriter.println( "val=" + val );<br />
printWriter.println( "grouplist[" + j+ "]=" + grouplist[j] );<br />
printWriter.close();<br />
if( val == grouplist[j] ){<br />
switch ( parseInt( j % 2 ) ){<br />
case 0:<br />
fill.set( 100,100,100 );<br />
break;<br />
case 1:<br />
fill.set( 200,200,200 );<br />
break;<br />
default:<br />
fill.set( 0,0,0 );<br />
break;<br />
}<br />
fill.setTransparency(127);<br />
} <br />
}<br />
} <br />
}
mwilliams
Glad you found the issue. Let us know whenever you have questions!