Change pie chart label with multiple values

kclarkkclark BIRT GuruEM
edited November 1, 2013 in DevShare Downloads
Sometimes you need to change the label in a pie chart, this can easily be done

in the beforeDrawDataPointLabel(). What if you've also included value data with

the category data in the label? By the time you get the label value in

beforeDrawDataPointLabel() BIRT has put all the label information in the same

string. This example shows how you can change the category data in your label

without overwriting the rest of the string. It can be done with the following

function beforeDrawDataPointLabel( dph, label, icsc )
  var entireLabel = label.getCaption().getValue();
  var firstValue;
  var secondValue = " United States";
  if("USA", entireLabel) > 0) {
    var endPosition ="USA", entireLabel) - 1;
    firstValue = BirtStr.left(entireLabel, endPosition);
    label.getCaption().setValue(firstValue + secondValue);
} looks to see if the given value is in the string and

returns the starting position. If the string is not found -1 is returned.

Since tells me where the string is located and I know that

it's the last value I can use this to tell me where the end of the value data

is located and store it in endPosition.

Then I can use BirtStr.left() to store everything from the left most value to

endPosition and finally change the label with

label.getCaption().setValue(firstValue + secondValue);

Kristopher Clark

Actuate Corporation – The BIRT Company™ |


My Blog



Sign In or Register to comment.