Jasper reports 如何将区域设置设置为条形图中的标签?
我正在显示条形图,并试图让条形图上方的标签以正确的区域设置显示(它们是浮动)。我正在JasperSoft Studio 6.2.0中开发。我将全局和/或报告(执行时间)区域设置为Jasper reports 如何将区域设置设置为条形图中的标签?,jasper-reports,bar-chart,jfreechart,Jasper Reports,Bar Chart,Jfreechart,我正在显示条形图,并试图让条形图上方的标签以正确的区域设置显示(它们是浮动)。我正在JasperSoft Studio 6.2.0中开发。我将全局和/或报告(执行时间)区域设置为en_-US,但标签仍显示在我的Windows区域设置中(nl_-nl)。然后将标签表达式设置为 new DecimalFormat("#,##0.0##;(#,##0.0##-)").format($F{Hours}) 但它仍然在Windows区域设置中。仅当我将标签表达式显式设置为en_USlocale时: Num
en_-US
,但标签仍显示在我的Windows区域设置中(nl_-nl
)。然后将标签表达式设置为
new DecimalFormat("#,##0.0##;(#,##0.0##-)").format($F{Hours})
但它仍然在Windows区域设置中。仅当我将标签表达式显式设置为en_US
locale时:
NumberFormat.getInstance(Locale.US).format($F{Hours})
我得到正确的结果了吗。在其他位置(文本字段),设置格式模式(例如,设置为“#,#0.0##”(#,#0.0#-)”
)将导致应用正确的区域设置。在条形图设置中,没有办法以相同的方式指定模式,这就是为什么我尝试在代码中这样做
这是一个bug还是我遗漏了什么?
< P>是的,我验证过了,JaspApple报告在生成图表时不使用它的代码> $p{RePrimeLoaLe}}/Cord>,我几乎认为它是一个bug。他们使用metods生成不支持传递区域设置的图表,但可以自动生成具有正确区域设置的自定义程序 要在图表标签中获得所需的Locale
,您的选项如下
设置整个应用程序的默认区域设置
Locale.setDefault(Locale.US);
有关启动时传递参数的其他方法,请参见
如果只想更改图表中标签的区域设置
,则需要创建
条形图示例
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>
..
..
我知道我可以使用NumberFormat.getInstance({REPORT_LOCALE}).format({Hours})
,但这不允许我设置模式,而且无论如何都很不理想。你可以使用$P{REPORT_format_FACTORY}.createNumberFormat({REPORT#,#0.0###,(#,#0.0#,##,#0.0#,#,#,#工厂#)。createNumberFormat({创建一个新的报表格式,{houre}),从性能的角度来看,这显然不是理想的。这确实是一个bug,修复了data67,谢谢。那么,现在如何在自定义程序中获取区域设置?***公共类AssetChartMod实现JRChartCustomizer{****public void customize(JFreeChart图表,JRChart Jaspercart){