atom feed2 messages in org.apache.wicket.usersa way to show jfreechart tooltip on t...
FromSent OnAttachments
rolandpengOct 7, 2008 11:50 pm 
rolandpengOct 8, 2008 12:19 am 
Subject:a way to show jfreechart tooltip on the image
From:rolandpeng (ml-n@n2.nabble.com)
Date:Oct 7, 2008 11:50:31 pm
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().

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