How to format series labels of a BIRT chart by script

孤人 提交于 2019-12-11 09:39:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!