问题描述
我有一个StackedXYAreaChart,如下所示:
I have a StackedXYAreaChart that looks like the following:
如何格式化Y轴单位,使它们均匀间隔并以一定间隔显示?例如,我不想以1的增量显示单位(例如0, 1, 2, 3, ... 100
),而是要以10或25的增量显示单位(例如0, 25, 50, 75, 100
).谢谢!
How do I format the Y-axis units so that they are evenly spaced out and are displayed at certain intervals? For example, instead of displaying units in increments of 1 (e.g. 0, 1, 2, 3, ... 100
), I want to display units in increments of 10 or 25 (e.g., 0, 25, 50, 75, 100
). Thanks!
推荐答案
我找到了自己的问题的解决方案.我正在使用CustomTickUnit
来格式化数字并在后缀中添加单位,例如1000000
变为1 GB
.
I found a solution to my own question. I'm using a CustomTickUnit
that formats numbers and adds units to the suffix, e.g. 1000000
becomes 1 GB
.
我用以下代码设置了刻度单位,它们将它们均匀地隔开并对其进行了适当的格式化,以使它们易于阅读:
I set up my tick units with the following code, which spaced them out evenly and formatted them appropriately so that they are very readable:
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);
}
这篇关于JFreeChart和Y轴单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!