JFreechart刻度单位 [英] JFreechart tick units
问题描述
我正在使用以下代码,这些代码是我从网上发布的
I am using the following code which i got off the web
TickUnits units = new TickUnits();
DecimalFormat df1 = new DecimalFormat("$0");
DecimalFormat df2 = new DecimalFormat("$0.00");
// we can add the units in any order, the TickUnits collection will
// sort them...
units.add(new NumberTickUnit(100, df1, 0));
units.add(new NumberTickUnit(50, df1, 0));
units.add(new NumberTickUnit(20, df1, 0));
units.add(new NumberTickUnit(10, df1, 0));
units.add(new NumberTickUnit(5, df1, 0));
units.add(new NumberTickUnit(2, df1, 0));
units.add(new NumberTickUnit(1, df1, 0));
由于我是个新手,所以我不理解这段代码的实际作用.我以为它会在 y 轴上设置值,但事实并非如此,因为在 y 轴上有超过100美元的值.这段代码究竟是做什么的. (准确的是刻度单位.它是在轴上定义了标签还是在这里我弄错了?)
As I am very new, I don't understand what this piece of code actually does. I Thought that it sets the values on the y axis, but that does not seem to be the case as there are values exceeding 100 dollars on the y axis. What exactly does this piece of code do. (Also what exactly is tick units. Does it define the labels on the axes or am I mistaken here).
推荐答案
是的,TickUnits
定义了Axis
标签的格式,但是完整的说明超出了Stackoverflow的范围. 开发人员指南 †具有决定性,但可以证明有助于检查为特定Axis
子类返回TickUnitSource
的方法.例如,NumberAxis中的"nofollow noreferrer> createIntegerTickUnits()
,以及
Yes, TickUnits
define the format of Axis
labels, but a complete explication is beyond the scope of Stackoverflow. The developer guide† is dispositive, but it may prove instructive to examine the methods that return a TickUnitSource
for a particular Axis
subclass. For example, the source code for createIntegerTickUnits()
in NumberAxis
, along with NumberTickUnitSource
引用的示例存在缺陷,因为它忽略了用户的语言环境.
The example cited is flawed in that it ignores the user's locale.
附录:如果要使用本地化的货币格式,请覆盖默认的Number
格式程序.
Addendum: If you want localized currency format, override the default Number
formatter.
XYPlot plot = chart.getXYPlot();
NumberAxis range = (NumberAxis) plot.getRangeAxis();
range.setNumberFormatOverride(NumberFormat.getCurrencyInstance());
† 免责声明:不隶属于Object Refinery Limited;只是一个满意的客户,贡献很小.
这篇关于JFreechart刻度单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!