candlestick and MondayThroughFridayTimeline

Discussion about JFreeChart related to stockmarket charts.
Locked
hl_107
Posts: 5
Joined: Wed Mar 10, 2010 8:28 pm
antibot: No, of course not.

candlestick and MondayThroughFridayTimeline

Post by hl_107 » Sun May 02, 2010 10:54 pm

i was trying to get rid of the gaps(weekends) from a candlestick chart, by

((DateAxis) plot.getDomainAxis()).setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());

it ran into busy loop or something when the dataset size is more than 70-80. did i miss something or this might be a potential issue with the SegmentedTimeline class? it all works if i don't apply the newMondayThroughFridayTimeline thing.

thanks for your help.
Jeff

hl_107
Posts: 5
Joined: Wed Mar 10, 2010 8:28 pm
antibot: No, of course not.

Re: candlestick and MondayThroughFridayTimeline

Post by hl_107 » Wed Dec 01, 2010 10:56 pm

there seems to be a bug in DateAxis.java, at least in my case. i filed a bug to sourceforge.

the following line may adjust the date to a previous hidden date, which can lead to infinite loop.
tickDate = correctTickDateForPosition(tickDate, unit, this.tickMarkPosition);

Code: Select all

protected List refreshTicksHorizontal(Graphics2D g2,
                Rectangle2D dataArea, RectangleEdge edge) {

        List result = new java.util.ArrayList();

        Font tickLabelFont = getTickLabelFont();
        g2.setFont(tickLabelFont);

        if (isAutoTickUnitSelection()) {
            selectAutoTickUnit(g2, dataArea, edge);
        }

        DateTickUnit unit = getTickUnit();
        Date tickDate = calculateLowestVisibleTickValue(unit);
        Date upperDate = getMaximumDate();

        while (tickDate.before(upperDate)) {
            // could add a flag to make the following correction optional...
            tickDate = correctTickDateForPosition(tickDate, unit,
                    this.tickMarkPosition);

            long lowestTickTime = tickDate.getTime();
            long distance = unit.addToDate(tickDate, this.timeZone).getTime()
                    - lowestTickTime;
            int minorTickSpaces = getMinorTickCount();
            if (minorTickSpaces <= 0) {
                minorTickSpaces = unit.getMinorTickCount();
            }
            for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
                long minorTickTime = lowestTickTime - distance
                        * minorTick / minorTickSpaces;
                if (minorTickTime > 0 && getRange().contains(minorTickTime)
                        && (!isHiddenValue(minorTickTime))) {
                    result.add(new DateTick(TickType.MINOR,
                            new Date(minorTickTime), "", TextAnchor.TOP_CENTER,
                            TextAnchor.CENTER, 0.0));
                }
            }

            if (!isHiddenValue(tickDate.getTime())) {
                // work out the value, label and position
                String tickLabel;
                DateFormat formatter = getDateFormatOverride();
                if (formatter != null) {
                    tickLabel = formatter.format(tickDate);
                }
                else {
                    tickLabel = this.tickUnit.dateToString(tickDate);
                }
                TextAnchor anchor = null;
                TextAnchor rotationAnchor = null;
                double angle = 0.0;
                if (isVerticalTickLabels()) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                    if (edge == RectangleEdge.TOP) {
                        angle = Math.PI / 2.0;
                    }
                    else {
                        angle = -Math.PI / 2.0;
                    }
                }
                else {
                    if (edge == RectangleEdge.TOP) {
                        anchor = TextAnchor.BOTTOM_CENTER;
                        rotationAnchor = TextAnchor.BOTTOM_CENTER;
                    }
                    else {
                        anchor = TextAnchor.TOP_CENTER;
                        rotationAnchor = TextAnchor.TOP_CENTER;
                    }
                }

                Tick tick = new DateTick(tickDate, tickLabel, anchor,
                        rotationAnchor, angle);
                result.add(tick);

                long currentTickTime = tickDate.getTime();
                tickDate = unit.addToDate(tickDate, this.timeZone);
                long nextTickTime = tickDate.getTime();
                for (int minorTick = 1; minorTick < minorTickSpaces;
                        minorTick++){
                    long minorTickTime = currentTickTime
                            + (nextTickTime - currentTickTime)
                            * minorTick / minorTickSpaces;
                    if (getRange().contains(minorTickTime)
                            && (!isHiddenValue(minorTickTime))) {
                        result.add(new DateTick(TickType.MINOR,
                                new Date(minorTickTime), "",
                                TextAnchor.TOP_CENTER, TextAnchor.CENTER,
                                0.0));
                    }
                }

            }
            else {
                tickDate = unit.rollDate(tickDate, this.timeZone);
                continue;
            }

        }
        return result;

    }

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

Re: candlestick and MondayThroughFridayTimeline

Post by skunk » Thu Dec 02, 2010 2:50 pm

Its a known bug. See this thread for more info and some possible workarounds
http://www.jfree.org/phpBB2/viewtopic.p ... inite+loop

sutindaya
Posts: 2
Joined: Thu Apr 21, 2011 9:31 am
antibot: No, of course not.

Re: candlestick and MondayThroughFridayTimeline

Post by sutindaya » Tue Apr 26, 2011 7:10 am

it ran into busy loop or something when the dataset size is more than 70-80. did i miss something or this might be a potential issue with the SegmentedTimeline class? it all works if i don't apply the newMondayThroughFridayTimeline thing.
_________________________
SEO Manchester

itsmaddy
Posts: 10
Joined: Wed Dec 15, 2010 1:05 pm
antibot: No, of course not.

Re: candlestick and MondayThroughFridayTimeline

Post by itsmaddy » Tue Apr 26, 2011 12:53 pm

I also wanted to apply MondayThroughFridayTimeline in my project but when i use it hangs.
and if i remove it everything works fine.
Is there any solution to it?

Locked