Home Analytics DevShare
The community of Analytics developers are invited to follow and participate in the developer network.
OpenText technical experts collaborate with supported customers and partners in the Magellan product area.

Change pie chart label with multiple values

kclarkkclark BIRT GuruEM
edited November 1, 2013 in DevShare
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 />
function beforeDrawDataPointLabel( dph, label, icsc )
  var entireLabel = label.getCaption().getValue();
  var firstValue;
  var secondValue = " United States";
  if(BirtStr.search("USA", entireLabel) &gt; 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);

Kristopher Clark

Actuate Corporation – The BIRT Company™

http://www.actuate.com | http://birtondemand.com


My Blog



Sign In or Register to comment.