我有一个StackedXYAreaChart,如下所示:
如何格式化Y轴单位,使它们均匀分布并以一定的间隔显示?例如,代替以1的增量显示单位(例如0, 1, 2, 3, ... 100
),我想以10或25的增量(例如,0, 25, 50, 75, 100
)显示单位。谢谢!
答案 0 :(得分:4)
我找到了解决自己问题的方法。我正在使用CustomTickUnit
格式化数字并在后缀中添加单位,例如1000000
变为1 GB
。
我使用以下代码设置我的刻度单位,将它们均匀分开并适当地格式化它们以使它们非常易读:
public void setupRangeAxis(NumberAxis rangeAxis) {
final TickUnits standardUnits = new TickUnits();
standardUnits.add(new CustomTickUnit(1));
standardUnits.add(new CustomTickUnit(10));
standardUnits.add(new CustomTickUnit(100));
standardUnits.add(new CustomTickUnit(1000)); // Kilo
standardUnits.add(new CustomTickUnit(10000));
standardUnits.add(new CustomTickUnit(100000));
standardUnits.add(new CustomTickUnit(1000000)); // Mega
standardUnits.add(new CustomTickUnit(10000000));
standardUnits.add(new CustomTickUnit(100000000));
standardUnits.add(new CustomTickUnit(1000000000)); // Giga
standardUnits.add(new CustomTickUnit(10000000000L));
standardUnits.add(new CustomTickUnit(100000000000L));
standardUnits.add(new CustomTickUnit(1000000000000L)); // Tera
standardUnits.add(new CustomTickUnit(10000000000000L));
standardUnits.add(new CustomTickUnit(100000000000000L));
standardUnits.add(new CustomTickUnit(1000000000000000L)); // Peta
standardUnits.add(new CustomTickUnit(10000000000000000L));
standardUnits.add(new CustomTickUnit(100000000000000000L));
standardUnits.add(new CustomTickUnit(1000000000000000000L)); // Exa
rangeAxis.setStandardTickUnits(standardUnits);
}
答案 1 :(得分:1)
假设NumberAxis
,将刻度单位设置为25.有一个相关示例here。
axis.setTickUnit(new NumberTickUnit(25));
答案 2 :(得分:1)
CategoryPlot plot = chart.getCategoryPlot();
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setTickUnit(new NumberTickUnit(300));