请如何更改Y轴以使数据显示的位数相同。

This is what I have on my graph

这是产生图的那部分的代码

final CategoryPlot plot = (CategoryPlot)result.getPlot ();
plot.setBackgroundPaint(Color.BLACK);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setRange (1.2, 1.3);
rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits ());
rangeAxis.setTickUnit (new NumberTickUnit(0.005));


如您所见,我将起点固定为1.2,将终点固定为1.3,并将TickUnit定义为0.005。所以通常(我认为)我应该逐渐喜欢:
1.2 1.205 1.210 ... 1.305


This is what I would like to obtain

如何修改代码以获取带有渐变值的Y轴?
谢谢

我想我已经找到了解决方案

DecimalFormat df = new DecimalFormat("0.000");
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setRange (1.200, 1.300);
rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits ());
rangeAxis.setTickUnit (new NumberTickUnit(0.005, df, 0));


它似乎工作正常。
谢谢

最佳答案

图表轴将接受一个java.text.NumberFormat实例,它将用于格式化标签。为此,请尝试将以下几行添加到您的代码中:

DecimalFormat newFormat = new DecimalFormat("0.000");
rangeAxis.setNumberFormatOverride(newFormat);

10-06 09:31