Changing background color for a portion of the plot

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
avanidhar
Posts: 16
Joined: Wed Jun 11, 2008 10:47 pm

Changing background color for a portion of the plot

Post by avanidhar » Mon Nov 10, 2008 8:52 pm

Hi All,

I am using JFreeChart for a medical analysis toolkit and need to select a region to do some manipulations. Once i select it, I need to set the background color of the region to do something else ( this is plainly an interface issue, but really important).
Here is the code snippet which does this.

Code: Select all

else if(e.isAltDown()){
                    this.currentMouseMode = MOUSEMODE.PICKREGION;
                    double x = this.renderer.getPlot().getDomainCrosshairValue();
                    double y = this.renderer.getPlot().getRangeAxis().getUpperBound();
                    double width = e.getX()-x;
                    double height = y - this.renderer.getPlot().getRangeAxis().getLowerBound();
                    this.mouseDragPreviousPoint = new Point();
                    this.mouseDragPreviousPoint.setLocation(x, y);
                    Dimension d = new Dimension();
                    d.setSize(width, height);
                    /*
                        I am stuck at obtaining the graphics2d context!!!
                    */
                    Rectangle r = new  Rectangle(this.mouseDragPreviousPoint,d);
                    this.renderer.getPlot().drawBackground(g2, r);
                    
                    
                }
I am using JFreechart-1.0.11, if that helps.
Basically, I am using the Crosshair and the clicked point to form a rectangle. So now, I have the rectangle area to color, but am stuck at setting the background color of the particular area. Any suggestions would be greatly appreciated.

Avanidhar

develop
Posts: 296
Joined: Wed Mar 23, 2005 10:01 pm

Post by develop » Tue Nov 11, 2008 8:16 pm

another approach would be to use to markers. once you get x and y value of chart. try adding appropriate marker (domain/Range) and see if that works.

Hope this helps.

Locked