I want to use 2 background images on my chart -- one image in the lower right and a different image in the top half of chart.
The calls to:
plot.setBackgroundImage(image);
plot.setBackgroundImageAlignment(org.jfree.ui.Align.BOTTOM_RIGHT);
do not seem to account for 2 images in the same graph. Is that right?
Does anyone know of a workaround I can use to get this done?
Edit: I just found the ImageTitle in the API so I am going to try that. If anyone has an example, that'd be great. I searched the jfreechart sample code and did not find it.
Edit: Solved. Easier than I thought!
Here is the code to help someone else:
Code: Select all
try {
File file = new File("small_img.png");
Image image = ImageIO.read(file);
plot.setBackgroundPaint(null);
plot.setBackgroundImage(image);
plot.setBackgroundImageAlignment(org.jfree.ui.Align.BOTTOM_RIGHT);
// 0 is transparent (invisible), 1 is opaque (fully visible)
plot.setBackgroundImageAlpha(0.4f);
// second image
file = new File("center_img.png");
image = ImageIO.read(file);
ImageTitle imageTitle = new ImageTitle(image);
XYTitleAnnotation annotation = new XYTitleAnnotation(0.5, 0.5, imageTitle);
plot.addAnnotation(annotation);
} catch (IOException e) {
e.printStackTrace();
}
Since the second image is a title image and not a background image, the graph (plot) is overlaid by the title image in a small portion of the plot. Not good. Anyone know of a workaround? I may have to give up on this idea.
Mark James