Hi,
Could anyone show me how to add a logo/image (gif or jpg) in a corner of a chart? I've found how to do a background but would be interested in simply adding a logo on some charts.
Many thanks
Benoit.
Adding image/logo to a chart.
-
- Posts: 40
- Joined: Fri Apr 11, 2003 5:29 pm
- Location: London, yes England (where else?)
- Contact:
More to the point... XYImageAnnotation?
Hi,
Looking a bit further...I've come accross XYImageAnnotation. Unless I am mistaken, this class is not in the doc and no example shows how to use it. So.., I could not resist and I tried it of course.
Sorry for the blunt question but: does it work?
Having called
I tried the following:
The getLogo() returns an Image and it works as I can use it to put the image as a background.
Should I do anything different in order to use the ImageAnnotation?
Should it be called before the chart is generated? (something I am always unsure...)
Should the draw method be called on the annotation? Or is it done internally.
Any pointer/suggestion would be very welcome.
Many thanks
Benoit.
Looking a bit further...I've come accross XYImageAnnotation. Unless I am mistaken, this class is not in the doc and no example shows how to use it. So.., I could not resist and I tried it of course.
Sorry for the blunt question but: does it work?
Having called
Code: Select all
ChartFactory.createTimeSeriesChart(....)
Code: Select all
XYPlot plot = chart.getXYPlot();
XYAnnotation annotation = new XYImageAnnotation(250,250,getLogo());
plot.addAnnotation(annotation);
...
ChartUtilities.saveChartAsJPEG(file, chart, chartWidth, chartHeight);
Should I do anything different in order to use the ImageAnnotation?
Should it be called before the chart is generated? (something I am always unsure...)
Should the draw method be called on the annotation? Or is it done internally.
Any pointer/suggestion would be very welcome.
Many thanks
Benoit.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
The code you posted should draw the image centered on the point (250, 250) on your chart (where the x and y coordinates are measured against the axes). So the thing to check is that (250, 250) falls within the ranges on your axes.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 40
- Joined: Fri Apr 11, 2003 5:29 pm
- Location: London, yes England (where else?)
- Contact:
Re:Adding image/logo to a chart.
Hi David,
Many thanks for your prompt reply. It works!
It was not clear to me that the points were referring to values of the X Axis ie in my case of a TimeSeriesChart, the X value should be related to the java Date.getTime() value... which is a 'big' number for say Today Feb 25 2004. and same for the Y Axis; So (10,10) is not the absolute co-ordinates but the one where X=10 and Y=10.
Is there a way to:
1/ Use absolute co-ordinates regardless of values of the x and y axis? Say given a chart of 640 by 480, I want to see a logo centered around 320/240?
2/ put a logo outside the plot area, say in a corner of the whole chart?
many thanks
best regards,
Benoit.
Many thanks for your prompt reply. It works!
It was not clear to me that the points were referring to values of the X Axis ie in my case of a TimeSeriesChart, the X value should be related to the java Date.getTime() value... which is a 'big' number for say Today Feb 25 2004. and same for the Y Axis; So (10,10) is not the absolute co-ordinates but the one where X=10 and Y=10.
Is there a way to:
1/ Use absolute co-ordinates regardless of values of the x and y axis? Say given a chart of 640 by 480, I want to see a logo centered around 320/240?
2/ put a logo outside the plot area, say in a corner of the whole chart?
many thanks
best regards,
Benoit.
-
- Posts: 115
- Joined: Fri Mar 14, 2003 3:13 pm
- Location: London, England
- Contact:
London, where?
London, Ontario?
http://www.city.london.on.ca/Mapphoto/globe.htm
P.S. Does the X stand for xhenseval?
http://www.city.london.on.ca/Mapphoto/globe.htm
P.S. Does the X stand for xhenseval?
-
- Posts: 15
- Joined: Thu Mar 27, 2003 10:06 am
Re:Adding image/logo to a chart.
Have a look at JFreeChart.setBackgroundImage() and JFreeChart.setBackgroundImageAlignment().benoitx wrote:2/ put a logo outside the plot area, say in a corner of the whole chart?
Here is an example.
HTH,
Klaus
-
- Posts: 40
- Joined: Fri Apr 11, 2003 5:29 pm
- Location: London, yes England (where else?)
- Contact:
Re:Adding image/logo to a chart
Hi Klaus,
Thanks for your suggestion & example. perfect!
Regards
Benoit.
Thanks for your suggestion & example. perfect!
Regards
Benoit.