Home
Analytics
Set pie chart slice color based on value
gdittmar
Hi all,
I am trying to figure out how to script my chart so that based on the label of a slice of the pie chart there is a specific color associated with that label. I found some examples:
http://balendra15.wordpress.com/2011/05/05/customizing-color-of-pie-depending-upon-values-in-birt-pie-charts-java-scripting-in-birt-pie-charts/
and
http://www.birt-exchange.org/org/forum/index.php/topic/25254-pie-chart-color-by-categories/
BUT these solutions throw an error
Cannot find function getBaseDisplayValue in object com.actuate.birt.flash.charts.xmldata.FlashChartDataPointHints@1edc5be. at line 16 of chart script:'' (Element ID:44)
Is there some API I need to import additionally to what is built in or?
Thanks!
Find more posts tagged with
Comments
mwilliams
What version of Actuate BIRT are you using?
gdittmar
version 11.0.3
Trying to hunt down to correct js call for the flash charts. I figured out after I posted that the code will work for standard charts.
gdittmar
Is there an online java doc for the jsapi? I havent been able to find it. In addition to the pie chart coloring I am trying to change the x-axis value labels on the fly as well in a script for a bar chart I have. I am mainly just not sure which methods I need to be changing code in to achieve these results.
mwilliams
Take a look at this, for the JSAPI stuff.
http://www.birt-exchange.com/be/documentation/R11SP3/ajc/help/wwhelp/wwhimpl/js/html/wwhelp.htm#href=javascriptapi/about-JavaScriptAPI.html
As for the bar chart, is it also a flash chart? Or a standard chart? Let me know. I'll take a look at the pie chart thing.
mwilliams
You can set the color of a specific category's flash chart slice with the following code:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawDataPoint( fcdph, fill, fcsc )
{
if (fcdph.getDataPointHints().getBaseDisplayValue() == "myCategory"){
fill.set(255,255,0);
}
}
</pre>
gdittmar
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="100169" data-time="1336591445" data-date="09 May 2012 - 12:24 PM"><p>
Take a look at this, for the JSAPI stuff.<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.com/be/documentation/R11SP3/ajc/help/wwhelp/wwhimpl/js/html/wwhelp.htm#href=javascriptapi/about-JavaScriptAPI.html'>http://www.birt-exchange.com/be/documentation/R11SP3/ajc/help/wwhelp/wwhimpl/js/html/wwhelp.htm#href=javascriptapi/about-JavaScriptAPI.html</a><br
/>
<br />
As for the bar chart, is it also a flash chart? Or a standard chart? Let me know. I'll take a look at the pie chart thing.<br /></p></blockquote>
<br />
Yeah ideally it will be the flash chart.
mwilliams
Can you describe the situation for changing the label in the bar chart?
gdittmar
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="100272" data-time="1336689845" data-date="10 May 2012 - 03:44 PM"><p>
Can you describe the situation for changing the label in the bar chart?<br /></p></blockquote>
<br />
So we have in our database a series of int values that correspond to a rating so 1 for bad 2 for moderate and 3 for good. Ideally I would like to be able to say build the bar chart using these integer values but then relabel them with the good bad and moderate equivalents on the fly. Granted this probably seems very odd but was a request of the client and we need these int values for processing in other parts of our reports so I dont see a way to easily move away from them without loosing functionality else where in the reports. Does that sort of make sense?
mwilliams
One thing you could easily do is to create a computed column in your dataSet that checks the int value and assigns the string value to that row. Then, you could use the new field in your chart.<br />
<br />
Another way I found you can change the values is in the afterDataSetFilled function:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function afterDataSetFilled( series, dataSet, fcsc )
{
if (series.getSeriesIdentifier() == ""){
temp = dataSet.getValues();
tempsize = temp.length;
i=0;
while (i<tempsize){
temp[i] = "100";
i++;
}
dataSet.setValues(temp);
}
}
</pre>
<br />
This just changes all the x-axis values to 100, but you could add more logic to change the values according to their current value.
gdittmar
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="100299" data-time="1336749652" data-date="11 May 2012 - 08:20 AM"><p>
One thing you could easily do is to create a computed column in your dataSet that checks the int value and assigns the string value to that row. Then, you could use the new field in your chart.<br />
<br />
Another way I found you can change the values is in the afterDataSetFilled function:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function afterDataSetFilled( series, dataSet, fcsc )
{
if (series.getSeriesIdentifier() == ""){
temp = dataSet.getValues();
tempsize = temp.length;
i=0;
while (i<tempsize){
temp[i] = "100";
i++;
}
dataSet.setValues(temp);
}
}
</pre>
<br />
This just changes all the x-axis values to 100, but you could add more logic to change the values according to their current value.<br /></p></blockquote>
<br />
I thought about doing something like that but I think I messed up my syntax on the computed column expression builder. I thought it would be something like have an if statement then somehow say return the associated string? Could you give a syntax example of that because that would probably be the easiest solution if possible.
gdittmar
<blockquote class='ipsBlockquote' data-author="'gdittmar'" data-cid="100317" data-time="1336758624" data-date="11 May 2012 - 10:50 AM"><p>
I thought about doing something like that but I think I messed up my syntax on the computed column expression builder. I thought it would be something like have an if statement then somehow say return the associated string? Could you give a syntax example of that because that would probably be the easiest solution if possible.<br /></p></blockquote>
<br />
nvm figured it out. thanks!
mwilliams
You're welcome! Let us know whenever you have questions!
gdittmar
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="100319" data-time="1336761214" data-date="11 May 2012 - 11:33 AM"><p>
You're welcome! Let us know whenever you have questions!
<br /></p></blockquote>
<br />
Hi mwilliams,<br />
<br />
I looked at the code and it looks like I explained it incorrectly. I was more curious I guess if there was a way to relabel the y axis tick marks as possible. Would it possibly be a similar script? I am going to try to use the computed column approach. Can a bar chart in birt handle a string for the y axis alright or might that render the lengths of the bars weird do you think?<br />
<br />
Thanks!
mwilliams
Oh. That definitely changes things up, a little. Changing the actual y-axis value might get you something you're not wanting. Actuate BIRT 11 SP4 will have HTML5 charts. Maybe they will be a bit more dynamic on the scripting side for your labels. I'll take a look at the y-axis issue and see what I can find. I'll let you know.