Example usage for org.jfree.chart.axis DateTickUnitType getCalendarField

List of usage examples for org.jfree.chart.axis DateTickUnitType getCalendarField

Introduction

In this page you can find the example usage for org.jfree.chart.axis DateTickUnitType getCalendarField.

Prototype

public int getCalendarField() 

Source Link

Document

Returns the calendar field.

Usage

From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeTimeChartData.java

private TickUnits getUnits(CalendarFieldSplitPeriod period) {
    int field = period.getField();
    boolean good_match = false;
    for (DateTickUnitType unit : new DateTickUnitType[] { DateTickUnitType.SECOND, DateTickUnitType.MINUTE,
            DateTickUnitType.HOUR, DateTickUnitType.DAY, DateTickUnitType.MONTH, DateTickUnitType.YEAR }) {
        if (field == unit.getCalendarField()) {
            TickUnits units = new TickUnits();
            int count = period.getCount();
            int nsplit = period.getNsplit();
            if (count == 1 && nsplit == 1) {
                return null; // let jfree work it out.
            }//  w  ww.jav a2 s.  co  m
            if (nsplit > 50) {
                return null; // period unit is too small
            }
            // include all multiples that are exact factors of count
            for (int i = 1; i <= count; i++) {
                if (count % i == 0) {
                    units.add(new DateTickUnit(unit, i));
                    if (i > 1 && (count / i) < 8) {
                        good_match = true;
                    }
                }
            }

            // now larger multiples of count that factor nsplit
            for (int i = 2; i < nsplit && i < 50; i++) {
                if (nsplit % i == 0) {
                    units.add(new DateTickUnit(unit, i * count));
                    if (i > 1 && (nsplit / i) < 8) {
                        good_match = true;
                    }
                }
            }

            if (good_match) {
                return units;
            }
            return null;
        }
    }
    return null;
}