我不确定,但我有一个例子。有一天,我需要根据时间创建水平数字。然后我创建了这个类:
public class TimeAxis {
public static TickUnitSource createTimeTickUnits() {
TickUnits units = new TickUnits();
TimeFormat format = new TimeFormat();
units.add(new NumberTickUnit(1, format, 2));
units.add(new NumberTickUnit(2, format, 2));
units.add(new NumberTickUnit(5, format, 5));
units.add(new NumberTickUnit(10, format, 2));
units.add(new NumberTickUnit(20, format, 2));
units.add(new NumberTickUnit(60, format, 5));
units.add(new NumberTickUnit(120, format, 2));
units.add(new NumberTickUnit(240, format, 2));
units.add(new NumberTickUnit(540, format, 5));
units.add(new NumberTickUnit(1080, format, 2));
units.add(new NumberTickUnit(2160, format, 2));
units.add(new NumberTickUnit(5400, format, 5));
units.add(new NumberTickUnit(10800, format, 2));
units.add(new NumberTickUnit(21600, format, 2));
units.add(new NumberTickUnit(54000, format, 5));
units.add(new NumberTickUnit(108000, format, 2));
units.add(new NumberTickUnit(216000, format, 2));
units.add(new NumberTickUnit(540000, format, 5));
units.add(new NumberTickUnit(1080000, format, 2));
units.add(new NumberTickUnit(2160000, format, 2));
units.add(new NumberTickUnit(5400000, format, 5));
units.add(new NumberTickUnit(10800000, format, 2));
units.add(new NumberTickUnit(21600000, format, 2));
units.add(new NumberTickUnit(54000000, format, 5));
units.add(new NumberTickUnit(108000000, format, 2));
units.add(new NumberTickUnit(216000000, format, 2));
units.add(new NumberTickUnit(540000000, format, 5));
units.add(new NumberTickUnit(1080000000, format, 2));
units.add(new NumberTickUnit(2160000000.0, format, 2));
units.add(new NumberTickUnit(5400000000.0, format, 5));
units.add(new NumberTickUnit(10800000000.0, format, 2));
return units;
}
}
然后,我创建了一个类来操作“TimeFormat”:
public class TimeFormat extends NumberFormat {
@Override
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
StringBuffer myReturn = new StringBuffer();
//here I have the source to transform time in seconds in that format: 12h25m35s
return myReturn;
}
@Override
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
return new StringBuffer();
}
@Override
public Number parse(String source, ParsePosition parsePosition) {
return 0;
}
}
最后,我设置了这个属性:
ValueAxis domainAxis = plot.getDomainAxis();
domainAxis.setStandardTickUnits(TimeAxis.createTimeTickUnits()); //Here sets the horizontal numbers
要设置垂直数字:
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(TimeAxis.createTimeTickUnits());
我希望有用