Java 如何在 Primefaces 图表中格式化轴标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23360491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to format axis labels in a Primefaces chart
提问by Shnkc
I am looking for a way to format axis labes. Here is how my chart is shown:
我正在寻找一种格式化轴标签的方法。这是我的图表的显示方式:
I want 5000000 to be shown as 50M or 50,000,000. I couldn't find any way to perform such important action. Code is in java. Any help is appreciated.
我希望 5000000 显示为 50M 或 50,000,000。我找不到任何方法来执行如此重要的操作。代码在java中。任何帮助表示赞赏。
回答by ankush yadav
You can use Use your lineChart with addition tag extender
in which you should provide java scripts for display with formatted String. i am using in my project and it working fine. xhtml code and java csripts as below.
您可以将 lineChart 与附加标签extender
一起使用,您应该在其中提供用于显示格式化字符串的 Java 脚本。我在我的项目中使用它并且工作正常。xhtml 代码和 java csripts 如下。
<p:lineChart id="linear" value="#{xxxxxxxx}"
legendPosition="e" title="Linear Chart" extender="overrideXAxis"
style="height:300px" />
<script>
function overrideXAxis() {
this.cfg.axes = {
yaxis : {
tickOptions : {
formatString : "%dM",
angle : 0
}
}
}
};
</script>
it will give you required output.
它会给你所需的输出。
回答by Dusan Kovacevic
To format yaxis numbers with digit grouping, add following to your custom extender
要使用数字分组格式化 yaxis 数字,请将以下内容添加到您的自定义扩展程序
this.cfg.axes.xaxis.tickOptions.formatString = "%'d"
this.cfg.axes.xaxis.tickOptions.formatString = "%'d"
(jqPlot uses single quote (') to format number with digit grouping)
(jqPlot 使用单引号 (') 用数字分组来格式化数字)
回答by Mateus Alexandre
With primefaces 5.1 just do this:
使用 primefaces 5.1 只需执行以下操作:
<p:chart type="line">
Using the new tag, and in the Java code just do this:
使用新标签,并在 Java 代码中执行以下操作:
lineCharModelFinanceiro = new LineChartModel();
lineCharModelFinanceiro.getAxes().put(AxisType.X, new CategoryAxis("Meses"));
Axis yAxis = lineCharModelFinanceiro.getAxis(AxisType.Y);
yAxis.setTickFormat("%.2f");
yAxis.setLabel("Valor R$");
yAxis.setMin(-1);