XYBoxAnnotation

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
schultjd
Posts: 3
Joined: Sat May 02, 2009 2:00 pm

XYBoxAnnotation

Post by schultjd » Sat Nov 14, 2009 4:23 am

I created an XYLineChart and because the data was related to subsurface I inverted the range axis. Everything was fine - then I decided to add XYBoxAnnotation and couldn't get it to show up. After re-trying the demo and getting it to work I decided to comment out the axis invert statement and there was the box anno. Is this a known bug or is there some workaround that I can use to get the boxanno to work with the inverted y axis?

Thanks

Paul Belleville
Posts: 15
Joined: Wed Nov 07, 2007 6:20 pm

Re: XYBoxAnnotation

Post by Paul Belleville » Fri Mar 12, 2010 1:56 am

I am having the same problem. Was there ever any resolution to this issue?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: XYBoxAnnotation

Post by paradoxoff » Sat Mar 13, 2010 11:19 am

I just checked the source code for XYBoxAnnotation.
The annotation creates a Rectangle by converting the x0, x1, y0 and y1 coordinates (which are in data space) to java2D space. If one of the axis is inverted, then either the width or the height of the resulting rectangle will be < 0.
Solution: add this block to the source of XYBoxAnnotation, ahead of the line Rectangle2D box = null;

Code: Select all

        if(transX0 > transX1){
            double temp = transX0;
            transX0 = transX1;
            transX1 = temp;
        }
        if(transY1 > transY0){
            double temp = transY0;
            transY0 = transY1;
            transY1 = temp;
        }
[edit: the source of XYBoxAnnotation needs to be edited, of course]

Locked