how to add background image

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Gloria

how to add background image

Post by Gloria » Mon Feb 03, 2003 1:31 pm

Hi All,

I want to add an image as background in the plot area of a combined chart(timeseries chart, vertical bar chart). How can I add it? Which java I need to modify? Thx!

Regards,
Gloria

David Gilbert

Re: how to add background image

Post by David Gilbert » Mon Feb 03, 2003 1:57 pm

Use the setBackgroundImage(...) method in the plot class. I don't think I've ever checked that it works for combined plots...it should, as long as you add the image to the relevant subplot.

Regards,

Dave Gilbert

Gloria

Re: how to add background image

Post by Gloria » Mon Feb 03, 2003 2:05 pm

Hi Dave,

I have checked the plot class, but I don't know how should I modify it to add my own background image...

public void setBackgroundImage(Image image) {
this.backgroundImage = image;
notifyListeners(new PlotChangeEvent(this));
}

Is that to change the variable image?
Thx!

Gloria

David Gilbert

Re: how to add background image

Post by David Gilbert » Mon Feb 03, 2003 2:09 pm

You don't need to modify the plot class. Just use that method to pass in a reference to your image, and the plot will display it for you.

Regards,

Dave

Gloria

Re: how to add background image

Post by Gloria » Mon Feb 03, 2003 3:05 pm

Hi Dave,

I've added these in my servlet, but it can't work, I can't see any image

Image image = Toolkit.getDefaultToolkit().getImage("D:/wallpaper/wallpaper1.jpg");

// make a combined plot...
CombinedXYPlot plot = new CombinedXYPlot(new HorizontalDateAxis("Date"), CombinedXYPlot.VERTICAL);
plot.add(subplot1, 3); // a weight of 3 (75%)
plot.add(subplot2, 1); // a weight of 1 (25%)
plot.setBackgroundImage(image);

Anything wrong in my code?
Thx

Regards,
Gloria

Gloria

Re: how to add background image

Post by Gloria » Mon Feb 03, 2003 3:37 pm

Hi Dave,

I can add the image finally, I found that I need to add the image to each subplot seperately. Thx!

Regards,
Gloria

Locked