Hi there,
is JFreeChart your only possible approach? Check out flot integration
from wicketstuff-core.
It draws nicer charts and you can update datasets sending json object
and redraw it by js.
Regards,
Wojtek
Swarnim Ranjitkar pisze:
I couldn't override getResourceState of DynamicImageResource as it new Resource
state uses variable from DynamicImageResource eg format. Instead i copied
DynamicImageResource class and made my own version of it and modified the
getResourceState() get method. When I changed the drop down I was expecting it
to call the geImageData but it wasn't calling it. Could you please advice.
Here is the modified method.
protected synchronized ResourceState getResourceState()
{
return new ResourceState()
{
private byte[] imageData;
private final String contentType = image/ + format;
@Override
public Time lastModifiedTime()
{
if (lastModifiedTime == null)
{
lastModifiedTime =
DynamicImageResource.this.lastModifiedTime;
if (lastModifiedTime == null)
{
lastModifiedTime = Time.now();
}
}
return lastModifiedTime;
}
@Override
public byte[] getData()
{
// here is what I made the change.
imageData = getImageData();
return imageData;
}
@Override
public String getContentType()
{
return contentType;
}
};
}
From my Image Class I called the copied version of in getImageResource() {
return new DynamicImageResource(){
public class TugboatChartImage extends NonCachingImage {
private int width;
private int height;
public TugboatChartImage(String id, JFreeChart chart, int width, int
height){
super(id, new Model(chart));
this.width = width;
this.height = height;
}
@Override
protected Resource getImageResource() {
return new DynamicImageResource(){//my copied version of DynamicResouce
@Override
protected byte[] getImageData() {
JFreeChart chart = (JFreeChart)getDefaultModelObject();
return toImageData(chart.createBufferedImage(width, height));
}
};
}
}
To: users@wicket.apache.org
From: craig.mcil...@openroadsconsulting.com
Subject: Re: Updating a Dynamic Image with AJAX (and JFreeChart)
Date: Fri, 13 Nov 2009 23:31:39 -0500
Look at the source of the DynamicImageResource class. The getResourceState
method does something like (sorry for the lame pseudocode) 'if image data is
null then save and return value of getImageData else return the previous image
data'. So its gonna call your getImageData() method once and save the value.
This falls in line with the super class's (DynamicWebResource) javadoc that
says:
very useful for things you generate dynamically, but reuse for a while after
that. If you need resources that stream directly and are not cached, extend
WebResource directly and implement Resouce.getResourceStream() yourself.
It has nothing to do with HTTP caching, which it looks like you're trying to
solve with your headers, but server-side caching. Anyways... in this case,
getResourceStream of WebResource ends up calling getResourceState of
DynamicImageResource. All you need to do is is override getResourceState (and
therefore kind of overrides the behavior of getResourceStream) of your
DynamicImageResource and ensure that it doesn't cache the result of
getImageData() and you should be set.
Craig
_
From: wicketnewuser [mailto:swarn...@hotmail.com]
To: users@wicket.apache.org
Sent: Fri, 13 Nov 2009 20:32:05 -0500
Subject: Re: Updating a Dynamic Image with AJAX (and JFreeChart)
I have same situation. I'm not able to refresh my image. But if i view the
image i do get refreshed image
Here is my code. Based on my dropdownchoice it should make new Jfreechart
and the image should refresh. I couldn't get it working so i wrapped the
image with in a span but it still doesn't work. TugboatChartImage extends
NonCachingImage . Can any one point out what I'm doing wrong
Chart chart1 = new Chart(this.getString(column1.toString()), Date,
Dollars);
final String yAxisType = linear;
final int smallChartWidth=400;
final int smallChartHeight=200;
JFreeChart jfChartOne = chart1.render(chartOneCollection, null, yAxisType,
smallChartWidth, smallChartHeight);
// make an image
final TugboatChartImage imageOne = new TugboatChartImage(chart1image,
jfChartOne, smallChartWidth, smallChartHeight);
final WebMarkupContainer chart1Span = new
WebMarkupContainer(chart1Span);
chart1Span.add(imageOne);
add(chart1Span);
// draw