1

我有一个 JFreeChart 标准 TimelineGraph。有一个 Y 轴,数字从 0 到 600,还有一个 X 轴显示您希望看到的时间段。

我已经实现了以下代码:

protected void setupDomainAxis() {
    final long periodMillis = to.toDate().getTime() - from.toDate().getTime();
    if (periodMillis <= DAY_IN_MILLIS) {
        DateAxis domainAxis = new DateAxis();
        domainAxis.setDateFormatOverride(new SimpleDateFormat(UserContext.getCurrentUser().getTimeFormat().getPattern()));
        domainAxis.setRange(new DateRange(from.toDate(), to.toDate()), true, true);
        domainAxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2));
        domainAxis.setMinorTickMarksVisible(true);
        domainAxis.setMinorTickCount(2);
        getPlot().setDomainAxis(domainAxis);
    }


    else if (periodMillis == 172799999) {

        PeriodAxis domainAxis = new PeriodAxis(null);
        PeriodAxisLabelInfo[] info = new PeriodAxisLabelInfo[1];
        info[0] = new PeriodAxisLabelInfo(Day.class,
                new SimpleDateFormat(UserContext.getCurrentUser().getDateFormat().getWeekdayPattern(), LocaleContextHolder.getLocale()));
        domainAxis.setLabelInfo(info);

        domainAxis.setMinorTickMarksVisible(true);
        domainAxis.setMinorTickMarkOutsideLength(1);
        domainAxis.setMinorTickCount(3);

        domainAxis.setRange(new DateRange(from.toDate(), to.toDate()), true, true);
        getPlot().setDomainAxis(domainAxis);
    }

}

该方法的第一部分效果很好。第一部分和第二部分之间的区别在于domainAxis.

作为一个DateAxis我可以设置setMinorTickCount(2);方法,但作为一个PeriodAxis我可以设置可见性、标记长度,但不能设置刻度数。

有人有想法吗?我不明白为什么,因为这两种 Axis 都继承自org.jfree.chart.axis.ValueAxis并拥有该setMinorTickCount(int count)方法。

4

0 回答 0