This is my sample code to to show jfreechart tooltip on the image.
The key is to override onComponentTagBody() and use replaceComponentTagBody().
Just post my tried to share.
There should be better way to tune the performance.
--source code here--
public class JFreeChartImage extends NonCachingImage {
private String imageMapId;
private int width;
private int height;
private JFreeChart chart;
private ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
public JFreeChartImage(String id, String imageMapId,
int width, int height) {
// super(id, new Model(defaultImage));
super(id);
this.imageMapId = imageMapId;
this.width = width;
this.height = height;
}
@Override
protected Resource getImageResource() {
Resource imageResource = null;
final JFreeChart chart = getChart();
imageResource = new DynamicImageResource() {
@Override
protected byte[] getImageData() {
ByteArrayOutputStream stream = new
ByteArrayOutputStream();
try {
if (chart != null) {
info.clear();
ChartUtilities.writeChartAsPNG(stream, chart, width,
height, info);
}
} catch (IOException e) {
System.out.println("IOException: " +
e.getMessage());
}
return stream.toByteArray();
}
}; return imageResource;
}
@Override
protected void onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag) {
JFreeChart chart = getChart();
if (chart == null)
return;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
if (chart != null) {
info.clear();
ChartUtilities.writeChartAsPNG(stream, chart,
width, height,
info);
}
} catch (IOException e) {
System.out.println("IOException: " + e.getMessage());
}
System.out.println(ChartUtilities.getImageMap(imageMapId,
info));
replaceComponentTagBody(markupStream, openTag, ChartUtilities
.getImageMap(imageMapId, info));
}
public JFreeChart getChart() {
return chart;
}
public void setChart(JFreeChart chart) {
this.chart = chart;
}
}
________________________________________
Public email at Nabble.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]