Tick marks for Quarterly data

Discussion about JFreeChart related to stockmarket charts.
Locked
HTPC2Good4U
Posts: 8
Joined: Mon Sep 18, 2006 8:38 pm

Tick marks for Quarterly data

Post by HTPC2Good4U » Mon Sep 18, 2006 8:43 pm

Hello. I have my tick units set to 3 months for a time series chart. By default, it shows labels at months 1, 4, 7, and 10. I want it to show labels at months 3, 6, 9, and 12.

How do I do this? Thanks!

HTPC2Good4U
Posts: 8
Joined: Mon Sep 18, 2006 8:38 pm

Post by HTPC2Good4U » Mon Oct 02, 2006 7:00 pm

Just to clarify, I'm using monthly data. What I want it to do is show March, June, September and December as the tick marks on the date axis. Instead, I am getting January, April, July and October.

Any help would be greatly appreciated!

HTPC2Good4U
Posts: 8
Joined: Mon Sep 18, 2006 8:38 pm

Post by HTPC2Good4U » Mon Oct 02, 2006 8:13 pm

I ended up solving the problem, which should also solve numerous people's problems with their tick marks not being generated on the months that they want.

Add the following code to DateAxis.java:

Code: Select all

    /** Controls the tick skew */
    private int TickSkewAdjust = 0;

    /**
     * Sets the tick skew.
     * 
     * @param skew  The amount to skew the tick start date by
     */
    public void setTickSkew(int skew) {
        TickSkewAdjust = skew;
    }

    /**
     * Retrieves the tick skew.
     * 
     * @return The amount the tick start date is skewed by
     */
    public int getTickSkew() {
        return TickSkewAdjust;
    }
Then modify the previousStandardDate method to the following:

Code: Select all

    protected Date previousStandardDate(Date date, DateTickUnit unit) {

        int milliseconds;
        int seconds;
        int minutes;
        int hours;
        int days;
        int months;
        int years;

        Calendar calendar = Calendar.getInstance(this.timeZone);
        calendar.setTime(date);
        int count = unit.getCount();
        int current = calendar.get(unit.getCalendarField());

        // THE FOLLOWING LINE HAS BEEN CHANGED
        int value = count * (current / count) + TickSkewAdjust;
Then, in your code, set the tick skew to -1, and your tick marks can now be generated on March, June, September and December.

[EDIT]

Clarification: In order to get March, June, September and December to show up as your tick marks, you must set auto tick marks to false, and your tick interval to 3 months.

[/EDIT]

[EDIT AGAIN]
I made a small glitch in my code. The glitch was that I was subtracting the tick skew when I should have been adding it. The code above is already corrected.
[/EDIT AGAIN]

HTPC2Good4U
Posts: 8
Joined: Mon Sep 18, 2006 8:38 pm

Post by HTPC2Good4U » Mon Oct 02, 2006 8:35 pm

Also, if you happen to have data that falls on the end of your domain range, you can modify the DateAxis code in refreshTicksHorizontal and refreshTicksVertical to allow for the tick to be generated at the end of the domain range. Just edit the first while loop in both functions to reflect this change:

Code: Select all

        while (tickDate.before(upperDate) || tickDate.getTime() == upperDate.getTime()) {


Locked