请问如何更改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));
它似乎工作正常。
感谢
答案 0 :(得分:4)
图表轴将接受java.text.NumberFormat
实例,它将用于格式化标签。为此,请尝试将以下行添加到代码中:
DecimalFormat newFormat = new DecimalFormat("0.000");
rangeAxis.setNumberFormatOverride(newFormat);