如何在条形图中将区域设置设置为标签? [英] How to set Locale to labels in Bar Chart?

查看:157
本文介绍了如何在条形图中将区域设置设置为标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在显示一个条形图,并尝试将标签显示在正确的区域设置上方(它们是浮点数)。我正在开发JasperSoft Studio 6.2.0。我将全局和/或报告(执行时)区域设置设置为 en_US ,但标签仍显示在我的Windows区域设置中( nl_NL )。然后我将标签表达式设置为

I am displaying a bar chart and trying to have the labels above bars displayed in correct locale (they are floats). I am developing in JasperSoft Studio 6.2.0. I set the global and/or the report (execution-time) locale to en_US, but the labels are still displayed in my Windows locale (nl_NL). I then set the label expression to

new DecimalFormat("#,##0.0##;(#,##0.0##-)").format($F{Hours})

但它仍然在Windows语言环境中。只有当我明确地将标签表达式设置为 en_US locale:

but it's still in Windows locale. Only when I explicitly set the label expression to en_US locale:

NumberFormat.getInstance(Locale.US).format($F{Hours})

我是否得到了正确的答案结果。在其他地方(TextFields),设置格式模式(例如,#,## 0.0 ##;(#,## 0.0 ## - ))会导致正确应用的语言环境。在条形图设置中,无法以相同的方式指定模式,这就是我尝试在代码中执行此操作的原因。

do I get the correct result. At other places (TextFields), setting the format pattern (e.g. to "#,##0.0##;(#,##0.0##-)") leads to the correct locale being applied. In bar chart settings, there is no way to specify the pattern in the same fashion, that's why I am trying to do that in code.

这是一个错误还是上午我错过了什么?

Is this a bug or am I missing something?

推荐答案

是的我已经验证,jasper报告不使用其 $ P {REPORT_LOCALE} 生成图表时我几乎认为它是一个错误。他们使用metods生成不支持传递Locale的图表,但是他们可以自动生成具有正确语言环境的自定义程序。

Yes I verified, jasper reports do not use its $P{REPORT_LOCALE} when generating the chart and I would almost consider it a bug. They use metods to generate the chart that does not support passing the Locale, but they could automatically generate customizers with correct locale.

获得所需区域设置在图表标签中您的选项是。

To get desired Locale in chart label your options are.

设置整个应用程序的默认语言环境

Locale.setDefault(Locale.US);

参见为其他方法设置java语言环境设置,作为启动时传递参数。

see Setting java locale settings for other methods as passing parameter when launching.

如果您只想更改您需要创建 =nofollow noreferrer> JRChartCustomizer

If you only want to change the Locale of the label in your chart you need to create a JRChartCustomizer

BarChart示例

public class MyLocaleCustomizer implements JRChartCustomizer{
    @Override
    public void customize(JFreeChart chart, JRChart jrchart) {
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        StandardCategoryItemLabelGenerator lg = new StandardCategoryItemLabelGenerator("{2}",NumberFormat.getNumberInstance(Locale.US));
        plot.getRenderer().setBaseItemLabelGenerator(lg);
    }
}

在jrxml中

<barChart>
    <chart customizerClass="MyLocaleCustomizer">
        ..
    </chart>
    ..
</barChart>

这篇关于如何在条形图中将区域设置设置为标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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