SegmentedTimeline.addException results in X-axis overlap

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
spiderman2
Posts: 2
Joined: Mon Nov 30, 2009 11:39 pm
antibot: No, of course not.

SegmentedTimeline.addException results in X-axis overlap

Post by spiderman2 » Tue Dec 01, 2009 12:10 am

I'm using 1.0.12, JDK 6.14

I am using the newFifteenMinuteTimeLine successfully, and removing market hours as well as weekends.

I also require removing Holidays (Thanks Giving, Christmas, etc). So I'm adding an exclusions (Nov 26th), and that also works successfully. However, the date label for the 26th still appears, and is displayed undernear the 27th. It's an overlapping effect. How can I fix this?

Exclusion code:

Code: Select all

Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2009);
cal.set(Calendar.MONTH, Calendar.NOVEMBER);
cal.set(Calendar.DAY_OF_MONTH, 26);
cal.set(Calendar.HOUR_OF_DAY, 9);
		
		
intraDayStockUS.addException(cal.getTimeInMillis(), cal.getTimeInMillis() + 21600000);
I've seen a similar problem on the board related to candle stick, but I feel this problem is more general than that.

Has anyone had any success with Holiday support in Jfreechart? Also, if this is an acknowldged bug, does it have a scope for being fixed?

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Re: SegmentedTimeline.addException results in X-axis overlap

Post by skunk » Tue Dec 01, 2009 2:41 pm

The tick drawing routines do not take excluded/exception segments into account. I use the following subclass as a workaround in my code. It simply iterates over the list of ticks returned and deletes any tick that would be overwritten by the next tick.

Code: Select all

chart.getXYPlot().setDomainAxis(new DateAxis(null) {
    protected java.util.List refreshTicksHorizontal(java.awt.Graphics2D g2, Rectangle2D dataArea,
                                                                          RectangleEdge edge) {
        java.util.List list = super.refreshTicksHorizontal(g2, dataArea, edge);
        if (list.size() > 1) {
            // remove ticks that are overwritten by the following tick
            FontMetrics fm = g2.getFontMetrics(g2.getFont());
            for (int i = 0; i < list.size() - 1; i++) {
                DateTick tick0 = list.get(i);
                double position0 = valueToJava2D(tick0.getDate().getTime(), dataArea, edge);
                DateTick tick1 = list.get(i+1);
                double position1 = valueToJava2D(tick1.getDate().getTime(), dataArea, edge);
                if ((position0 + (fm.stringWidth(tick0.getText()) / 2.0d)) >
                                       (position1 - (fm.stringWidth(tick1.getText()) / 2.0d))) {
                    list.remove(tick0);
                    i--;
                }
            }
        }
        return list;
    }
});

spiderman2
Posts: 2
Joined: Mon Nov 30, 2009 11:39 pm
antibot: No, of course not.

Re: SegmentedTimeline.addException results in X-axis overlap

Post by spiderman2 » Tue Dec 01, 2009 7:56 pm

This is fantastic, and worked great. Thanks!

Junaid
Posts: 13
Joined: Tue Jul 20, 2010 2:25 pm
antibot: No, of course not.
Contact:

Re: SegmentedTimeline.addException results in X-axis overlap

Post by Junaid » Thu Jul 22, 2010 9:22 am

Hi,

I am using a segmentedTimeLine to eliminate the holidays/days not required. But I am facing an issue of dates/time overlapping.

The solution suggested by skunk is not working for JFreeChart version 1.0.6. Is there a way to get rid of overlapping in version 1.0.6.?

Further I would like to know if version 1.0.13 is backward compatible with version 1.0.6.

Regards,
Junaid

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: SegmentedTimeline.addException results in X-axis overlap

Post by matinh » Fri Jul 23, 2010 7:23 am

Hi!

What's the concrete problem with 1.0.6? As JFreeChart's API usually changes in a backward compatible way I'd guess that it should work. On the other hand, why don't you update to the newest version? Just try it, it should work without modifications to your code.

You can find all the changes from 1.0.6 to 1.0.13 in the ChangeLog file.

hth,
- martin

Junaid
Posts: 13
Joined: Tue Jul 20, 2010 2:25 pm
antibot: No, of course not.
Contact:

Re: SegmentedTimeline.addException results in X-axis overlap

Post by Junaid » Mon Jul 26, 2010 1:56 pm

Hi,

Thanks matinh, for your reply. We have upgraded to 1.0.13.
The overlapping issue is resolved with the upgrade.

Regards,
Junaid

Locked