Pie Chart: Color by Categories
Hi, I'm using a multiple pie charts and the slices are colored based on what the value of the category series is. This is working as intended, but the question I have is can I specify the color based on the value of the category.
For instance, my current slices are 'Agree', 'Disagree' 'Strongly Agree'. Depending on the question, one of these responses may not be in the chart. So a blue slice in Chart A could mean 'Agree', but a blue slice in Chart B could mean 'Disagree', since the slices only look for the category. Is there a way I can specify the coloring to say, if response='Agree' then blue slice, if response='Disagree' then red slice? With multiple charts on a page, users would more than likely get confused seeing the different colors representing the same values.
Thanks,
Bryan
For instance, my current slices are 'Agree', 'Disagree' 'Strongly Agree'. Depending on the question, one of these responses may not be in the chart. So a blue slice in Chart A could mean 'Agree', but a blue slice in Chart B could mean 'Disagree', since the slices only look for the category. Is there a way I can specify the coloring to say, if response='Agree' then blue slice, if response='Disagree' then red slice? With multiple charts on a page, users would more than likely get confused seeing the different colors representing the same values.
Thanks,
Bryan
0
Comments
-
Hi,<br />
<br />
Yes. Add this to each of your charts (replace the 'R', 'G', 'B' with the RGB color values)<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>function beforeDrawLegendItem( lerh, bounds, icsc )
{
var seriesValue = lerh.getLabel().getCaption().getValue();
var fill = lerh.getFill();
if( seriesValue == "Agree" )
fill.set( R, G, B, 255 );
if( seriesValue == "Disagree" )
fill.set( R, G, B, 255 );
if( seriesValue == "Strongly Disagree" )
fill.set( R, G, B, 255 );
}
function beforeDrawDataPoint( dph, fill, icsc )
{
if( dph.getBaseDisplayValue() == 'Agree' ){
fill.set( R, G, B, 255 );
if( dph.getBaseDisplayValue() == "Disagree" )
fill.set( R, G, B, 255 );
if( dph.getBaseDisplayValue() == "Strongly Disagree" )
fill.set( R, G, B, 255 );
}</pre>
<br />
Hope that helps,<br />
Rich1 -
Thanks for the reply Rich, I haven't used the scripting in BIRT much, so I just want to clarify where I'm putting the script. The only place I've really seen scripting is the Script tab in the main view, so does it go there? I currently have the two functions set up on the onRender, which was the only option for the chart. Do I need to replace seriesValue with row['value'], or is it reading seriesValue directly from the pie chart from where I have it set?
Thanks again,
Bryan0 -
Yep, you'd just put Rich's script in your chart script by selecting the chart in your layout, then selecting the script tab. The onRender is the only method in the chart. "seriesValue" is being read from the legend label and then the color changed, based on that. You should just need to put this script in the chart's onRender and run it, as long as the category values (Agree, Diagree, Strongly Disagree) are in your chart exactly as Rich put them in the code!Warning No formatter is installed for the format ipb0
-
@RichT By any chance can we use hexa codes for colors instead of RGB?
0 -
Hi Nayak,
You've responded to a pretty old thread, so you likely won't get a response from the people involved in this discussion.
To answer your question, no you can't use hex codes, but hex codes directly translate to RGB numeric values.
For example, indigo is #2E0854. To convert that to a syntax for the fill.set() command, you'd use parseInt("2E",16) for R, parseInt("08",16) for G, and parseInt("54",16) for B. The 16 is to inform the function that you're converting from base 16
Warning No formatter is installed for the format ipb1
Categories
- All Categories
- 122 Developer Announcements
- 53 Articles
- 151 General Questions
- 146 Thrust Services
- 56 OpenText Hackathon
- 35 Developer Tools
- 20.6K Analytics
- 4.2K AppWorks
- 9K Extended ECM
- 917 Cloud Fax and Notifications
- 83 Digital Asset Management
- 9.4K Documentum
- 31 eDOCS
- 178 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 9 XM Fax
- Follow Categories