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)
How to get chart color from a database
Niox.79
<p>Hello,</p>
<p> </p>
<p>first I want to apologize for my bad english. Unfortunately, it's not my native language. but I'll try to describe my problem anyway.</p>
<p> </p>
<p>I have a report with some pie charts. Right now I use a script in order to determine the color of the charts</p>
<p> </p>
<blockquote class="ipsBlockquote">
<p><strong><span style="color:#7f0055;"><span style="font-family:consolas;"><span style="font-size:10pt;">function</span></span></span></strong><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;"> beforeDrawDataPoint( dph, fill, icsc )</span></span></span></p>
<p><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;">{</span></span></span></p>
<p><strong><span style="color:#7f0055;"><span style="font-family:consolas;"><span style="font-size:10pt;">if</span></span></span></strong><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;"> (dph.getBaseDisplayValue() == </span></span></span><span style="color:#2a00ff;"><span style="font-family:consolas;"><span style="font-size:10pt;">"done"</span></span></span><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;">){</span></span></span></p>
<p><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;"> fill.set(0,204,0);</span></span></span></p>
<p><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;">}</span></span></span></p>
<p><strong><span style="color:#7f0055;"><span style="font-family:consolas;"><span style="font-size:10pt;">else</span></span></span></strong> <strong><span style="color:#7f0055;"><span style="font-family:consolas;"><span style="font-size:10pt;">if</span></span></span></strong><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;"> (dph.getBaseDisplayValue() == </span></span></span><span style="color:#2a00ff;"><span style="font-family:consolas;"><span style="font-size:10pt;">"open"</span></span></span><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;">){</span></span></span></p>
<p><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;"> fill.set(getValueAt(status, color));</span></span></span></p>
<p> <span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;">}</span></span></span></p>
<p><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;">and </span></span></span></p>
<p><strong><span style="color:#7f0055;"><span style="font-family:consolas;"><span style="font-size:10pt;">function</span></span></span></strong><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;"> beforeDrawLegendItem( lerh, bounds, icsc )</span></span></span></p>
<p><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;">{</span></span></span></p>
<p><strong><span style="color:#7f0055;"><span style="font-family:consolas;"><span style="font-size:10pt;">if</span></span></span></strong><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;"> (lerh.getLabel().getCaption().getValue() == </span></span></span><span style="color:#2a00ff;"><span style="font-family:consolas;"><span style="font-size:10pt;">"done"</span></span></span><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;">){</span></span></span></p>
<p><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;"> lerh.getFill().set(0,204,0);</span></span></span></p>
<p><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;">}</span></span></span></p>
<p><strong><span style="color:#7f0055;"><span style="font-family:consolas;"><span style="font-size:10pt;">else</span></span></span></strong> <strong><span style="color:#7f0055;"><span style="font-family:consolas;"><span style="font-size:10pt;">if</span></span></span></strong><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;"> (lerh.getLabel().getCaption().getValue() == </span></span></span><span style="color:#2a00ff;"><span style="font-family:consolas;"><span style="font-size:10pt;">"open"</span></span></span><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;">){</span></span></span></p>
<p> <span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;">lerh.getFill().set(240,107,19);</span></span></span></p>
<p><span style="color:#000000;"><span style="font-family:consolas;"><span style="font-size:10pt;"> }</span></span></span></p>
<p> </p>
</blockquote>
<p> </p>
<p>And so on</p>
<p> </p>
<p>What I would like to know is whether it is possible to take the color from a database. For example: Take the color for value W from database X, table Y and column Z. The Colors are stored as Hex. Do I have to convert them in RGB first?</p>
<p> </p>
<p>Thanks in advance</p>
Find more posts tagged with
Comments
JFreeman
<p>From what I can tell you will need to convert to colors into RGB before they can be applied.</p>
<p> </p>
<p>As for obtaining the values from your database, there are a few ways this could be done. You could create a data set in your report to pull in the desired column from your database.</p>
<p> </p>
<p>Alternatively, you could use javascript to connect to your database directly to obtain those values.</p>
Niox
<p>Hi Jesse,</p>
<p> </p>
<p>i am a beginner and I do not know if I can do it. But I'll try. Thank you for your help.</p>
JFreeman
<p>You're welcome.</p>
<p> </p>
<p>Let us know if you have any additional questions.</p>
Matthew L.
<p>Niox,</p>
<p> </p>
<p>I wrote up a quick function that will do the conversion from Hex to RGB and set the value.</p>
<p>I also modified your code to use the example function.</p>
<p>See function comments for more details.</p>
<p>Hopefully this helps out.</p>
<pre class="_prettyXprint _lang-js">
function beforeDrawDataPoint( dph, fill, icsc ){
if (dph.getBaseDisplayValue() == "done"){
//fill.set(0,204,0);
hexSet(fill,"#00CC00");
}else if (dph.getBaseDisplayValue() == "open"){
//fill.set(getValueAt(status, color));
hexSet(fill,getValueAt(status, color)); //Assuming that getValueAt() returns a hex string
}
}
function beforeDrawLegendItem( lerh, bounds, icsc ){
if (lerh.getLabel().getCaption().getValue() == "done"){
//lerh.getFill().set(0,204,0);
hexSet(lerh.getFill(),"#00CC00");
}else if (lerh.getLabel().getCaption().getValue() == "open"){
//lerh.getFill().set(240,107,19);
hexSet(lerh.getFill(),"#F06B13");
}
}
//
//Please note that all custom code received from Actuate Support is officially untested and unsupported.
//This is meant for guidance purposes only and should not be implemented in a production environment without proper testing.
//This custom code is provided to you "AS IS", It is your own responsibility to maintain it if changes are required.
//
//The following function sets a RGB color from a Hex value.
//Parameters:
// obj (object) = Object to set value to.
// hex (string) = Hex value of color to set object to.
//
//Examples:
// hexSet(fill,"#484847");
// hexSet(lerh.getFill(),"#484847");
//
function hexSet(obj,hex){
var tmpHex = hex.charAt(0)=="#"?hex.substring(1,7):hex; //Remove # if exists
var r = parseInt(tmpHex.substring(0,2),16); //Get Red value, use radix 16 for hexadecimal conversion
var g = parseInt(tmpHex.substring(2,4),16); //Get Green value, use radix 16 for hexadecimal conversion
var b = parseInt(tmpHex.substring(4,6),16); //Get Blue value, use radix 16 for hexadecimal conversion
obj.set(r,g,b); //Set color
}
//
</pre>
Niox
<p><span><span>this is great.</span> <span>many</span> <span>thanks</span> <span>for</span> <span>your effort</span><span>.</span><br><br><span>currently</span> <span>I have no</span> <span>time</span> <span>for the</span> <span>project</span><span>.</span> <span>but I will</span> <span>test it</span> <span>as soon as possible</span><span>.</span> <span>I</span><span>'ll let</span> <span>you guys know</span> <span>if</span> <span>it worked</span></span>.</p>