| From | Sent On | Attachments |
|---|---|---|
| rolandpeng | Oct 7, 2008 11:50 pm | |
| rolandpeng | Oct 8, 2008 12:19 am |
| Subject: | a way to show jfreechart tooltip on the image | |
|---|---|---|
| From: | rolandpeng (rola...@cht.com.tw) | |
| Date: | Oct 8, 2008 12:19:06 am | |
| List: | org.apache.wicket.users | |
This is my sample code to to show jfreechart tooltip on the image. The key is to override onComponentTagBody() and use replaceComponentTagBody(). the parameter imageMapId used in ChartUtilities.getImageMap(imageMapId, info); should also markded in html file ,for example :imageMapId="tooltip",then </img>
remember that the </img> tag must leave open tag,not close tag( , else replaceComponentTagBody() will not work.
Just post my tried code 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; }
}
--
View this message in context:
http://www.nabble.com/a-way-to-show-jfreechart-tooltip-on-the-image-tp19873571p19873571.html
Sent from the Wicket - User mailing list archive at Nabble.com.





