如何通过脚本格式化BIRT图表的系列标签 [英] How to format series labels of a BIRT chart by script

查看:128
本文介绍了如何通过脚本格式化BIRT图表的系列标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图表报告,显示一段时间内的指标值.该指标是一个报告参数,可以表示百分比(%)或货币($)值.

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:

现在,我需要根据所选指标的类型来更改数据点标签的格式数.在BIRT设计器中,我默认定义了百分比格式:

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.

在交叉表的数据字段中,格式可以在"onCreate"事件中更改,例如:

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!

推荐答案

此问题已在openText论坛

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()));
}

这篇关于如何通过脚本格式化BIRT图表的系列标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆