Java JFreechart刻度单位
我正在使用我从网上下载的以下代码Java JFreechart刻度单位,java,jfreechart,Java,Jfreechart,我正在使用我从网上下载的以下代码 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 Number
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美元。这段代码到底做什么。(还有什么是勾号单位。它定义了轴上的标签,还是我弄错了)。是的,
TickUnits
定义了轴
标签的格式,但完整的解释超出了Stackoverflow的范围。该†是决定性的,但对于特定的Axis
子类,检查返回TickUnitSource
的方法可能有指导意义。例如,inNumberAxis
的源代码以及
引用的示例存在缺陷,因为它忽略了用户的区域设置
附录:如果需要本地化货币格式,请覆盖默认的Number
formatter
XYPlot plot = chart.getXYPlot();
NumberAxis range = (NumberAxis) plot.getRangeAxis();
range.setNumberFormatOverride(NumberFormat.getCurrencyInstance());
†免责声明:不隶属于Object Refinery Limited;只是一个满意的客户,贡献率很小。如果它定义了轴上的值,为什么我要观察超出此范围的值。
ValueAxis
使用它的TickUnitSource
自动设置范围标签,但您可以使用setRange()
覆盖此范围。添加更多的NumberTickUnit
实例会改变粒度;边界由数据集
确定。我正在创建上面程序中提到的自己的tickuit。我也使用了从20到70的设置范围。这仍然不能阻止超过70的值出现。我建议编辑您的问题,以澄清您的要求,并包括一个展示您的发现的图表。基于jfreechart(基于android)的afreechart大多数功能都是相同的,尽管其中一个或两个可能不同