Change pie chart label with multiple values
Sometimes you need to change the label in a pie chart, this can easily be done<br />
in the beforeDrawDataPointLabel(). What if you've also included value data with<br />
the category data in the label? By the time you get the label value in<br />
beforeDrawDataPointLabel() BIRT has put all the label information in the same<br />
string. This example shows how you can change the category data in your label<br />
without overwriting the rest of the string. It can be done with the following<br />
code.<br />
<br />
BirtStr.search() looks to see if the given value is in the string and <br />
returns the starting position. If the string is not found -1 is returned.<br />
<br />
Since BirtStr.search() tells me where the string is located and I know that<br />
it's the last value I can use this to tell me where the end of the value data<br />
is located and store it in endPosition.<br />
<br />
Then I can use BirtStr.left() to store everything from the left most value to<br />
endPosition and finally change the label with<br />
<br />
label.getCaption().setValue(firstValue + secondValue);
in the beforeDrawDataPointLabel(). What if you've also included value data with<br />
the category data in the label? By the time you get the label value in<br />
beforeDrawDataPointLabel() BIRT has put all the label information in the same<br />
string. This example shows how you can change the category data in your label<br />
without overwriting the rest of the string. It can be done with the following<br />
code.<br />
function beforeDrawDataPointLabel( dph, label, icsc ) { var entireLabel = label.getCaption().getValue(); var firstValue; var secondValue = " United States"; if(BirtStr.search("USA", entireLabel) > 0) { var endPosition = BirtStr.search("USA", entireLabel) - 1; firstValue = BirtStr.left(entireLabel, endPosition); label.getCaption().setValue(firstValue + secondValue); } }<br />
<br />
BirtStr.search() looks to see if the given value is in the string and <br />
returns the starting position. If the string is not found -1 is returned.<br />
<br />
Since BirtStr.search() tells me where the string is located and I know that<br />
it's the last value I can use this to tell me where the end of the value data<br />
is located and store it in endPosition.<br />
<br />
Then I can use BirtStr.left() to store everything from the left most value to<br />
endPosition and finally change the label with<br />
<br />
label.getCaption().setValue(firstValue + secondValue);
Warning
No formatter is installed for the format ipb
0
Categories
- All Categories
- 108 Developer Announcements
- 53 Articles
- 106 General Questions
- 144 IM Services
- 43 OpenText Hackathon
- 32 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 899 Cloud Fax and Notifications
- 77 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 120 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management