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 chart 2
Chart chart2 = new Chart(this.getString(column2.toString()),
"Date",
"Count");
JFreeChart jfChartTwo = chart2.render(chartTwoCollection, null,
yAxisType,
smallChartWidth, smallChartHeight);
// make an image
TugboatChartImage imageTwo = new
TugboatChartImage("chart2image",
jfChartTwo, smallChartWidth, smallChartHeight);
add(imageTwo);
String filterStringList ="";
if (filterStringList!= null){
filterStringList =
report.getFilterParameterList().toString().replaceAll("\\[", "");
filterStringList = filterStringList.replaceAll("\\]",
"");
}
final DropDownChoice<TugboatReportData.ColumnName> chart1Select
= new
DropDownChoice<TugboatReportData.ColumnName>("chart1Select" ,new
PropertyModel(this, "column1"), TugboatReportData.trafficColumns,new
IChoiceRenderer() {
public Object getDisplayValue(Object obj) {
//this.getString give you value from the
propertyfile
return
ReportResultsPage.this.getString(((TugboatReportData.ColumnName)
obj).toString());
}
public String getIdValue(Object obj, int index) {
return obj.toString();
}
});
chart1Select.add(new
AjaxFormComponentUpdatingBehavior("onchange") {
protected void onUpdate(AjaxRequestTarget target) {
sortByColumn(displayRowSetFinal, column1);
Chart chart1R = new
Chart(ReportResultsPage.this.getString(column1.toString()), "Date",
"Dollars");
SwishTimeSeriesCollection chartOneCollectionR =
createChartCollection(report, originalRowSet, displayRowSetFinal.subList(0,
(originalRowSet.size() > 10) ? 9 : originalRowSet.size() - 1), column1);
logger.error(displayRowSetFinal);
JFreeChart jfChartOneR =
chart1R.render(chartOneCollectionR, null,
yAxisType, smallChartWidth, smallChartHeight);
imageOne.setDefaultModelObject(jfChartOneR);
imageOne.modelChanged();
chart1Span.modelChanged();
chart1Span.setOutputMarkupId(true);
imageOne.setOutputMarkupId(true);
target.addComponent(imageOne);
target.addComponent(chart1Span);
}
});
Jason Mihalick wrote:
>
> I am integrating JFreeChart into my application and I've followed the
> JFreeChart example on the wiki. That works very nicely. I was impressed.
> What I want to do now is update the graph that I display based on the
> selection from a drop down list. I've successfully added the
> DropDownChoice component and added a AjaxFormComponentUpdatingBehavior to
> it. I've verified that my onUpdate( AjaxRequestTarget ) method is being
> invoked and I'm receiving the updated value, which is very cool. Here is
> my onUpdate implementation for the DropDownChoice control:
>
> protected void onUpdate( AjaxRequestTarget target ) {
> log.debug( "graphStyles onUpdate invoked! SelectedGraphStyle = " +
> FieldResultsPanel.this.getSelectedGraphStyle() );
> FieldResultsPanel.this.updateGraph(); // Update the model and re-create
> the JFreeChart Image
>
> // fieldGraph is my JFreeChartImage instance (derived from Image)
> // This is supposed to indicate back to the browser that the image needs
> updated. I think this
> // is working properly
> target.addComponent( FieldResultsPanel.this.fieldGraph );
> }
>
> Even though I am updating the model of my JFreeChartImage, it appears that
> the getImageData method is never invoked afterwards.
>
> What do I need to do in order to get the image data to be re-read?
>
> Here is my JFreeChartImage class:
>
> public class JFreeChartImage extends Image {
>
> private static final Logger log = LoggerFactory.getLogger(
> JFreeChartImage.class );
>
> private int width;
> private int height;
>
> public JFreeChartImage( String id ) {
> super( id );
> }
>
> public JFreeChartImage( String id, int width, int height ) {
> this( id );
> this.width = width;
> this.height = height;
> }
>
> public JFreeChartImage( String id, JFreeChart chart, int width, int
> height ) {
> super(id, new Model( chart ) );
> this.width = width;
> this.height = height;
> }
>
> public Component setModel( JFreeChart chart ) {
> log.debug( "setModel invoked with chart: " + chart );
> return super.setModel( new Model( chart ) );
> }
>
> @Override
> protected Resource getImageResource() {
>
> return new DynamicImageResource(){
> private static final long serialVersionUID = 1L;
>
> @Override
> protected byte[] getImageData() {
> log.debug( "Invoking getImageData..." );
> JFreeChart chart = (JFreeChart)getModelObject();
> log.debug( "Chart object: " + chart );
> return toImageData( chart.createBufferedImage( width, height ) );
> }
>
> @Override
> protected void setHeaders( WebResponse response ) {
> if ( isCacheable() ) {
> super.setHeaders(response);
> } else {
> response.setHeader( "Pragma", "no-cache" );
> response.setHeader( "Cache-Control", "no-cache" );
> response.setDateHeader( "Expires", 0 );
> }
> }
> };
> }
>
> Any help is much appreciated!
>
> --
> Jason
>
--
View this message in context:
http://old.nabble.com/Updating-a-Dynamic-Image-with-AJAX-%28and-JFreeChart%29-tp12884455p26346217.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]