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://www.nabble.com/Updating-a-Dynamic-Image-with-AJAX-%28and-JFreeChart%29-tf4517009.html#a12884455
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to