问题
I have a chart report displaying indicator values over time. This indicator is a report parameter and can represent either a percent (%) or a currency ($) value.
Here is an example with a percent type:

Now i need to change the format number of datapoint labels depending on the type of the selected indicator. In BIRT designer i defined percent format by default:

The indicator type is extracted from a dataset and stored in a persistent global var, so that it can be accessed in chart scripts.
In a data field of a crosstab the format could be changed in "onCreate" event with something like:
this.getStyle().numberFormat="$ #,###";
But in chart scripts i can't find out a way to change the format number dynamically. Any suggestion will be appreciated!
回答1:
This question has been answered in openText forums here. We can format datapoint labels in the chart event "beforeDrawDataPointLabel". In this example below, the expected number format (for instance "$ #,###") is stored in a global variable "numberFormat":
importPackage(Packages.java.text);
nf = new DecimalFormat(getGlobalVariable("numberFormat"));
function beforeDrawDataPointLabel( dph, label, icsc ){
label.getCaption().setValue(nf.format(dph.getOrthogonalValue()));
}
来源:https://stackoverflow.com/questions/31404320/how-to-format-series-labels-of-a-birt-chart-by-script