Previous HOME Next

Plot targets can be placed inside of resizable containers for dynamic plot sizing. The examples here use the jQuery UI package for resizing functionality.

The first plot has good resize performance in Firefox, Safari and other canvas enabled browsers. The plot will resize dynamically with the container. IE performance will be slow since IE doesn't natively support the canvas element.

Resizing is handled by binding a handler to the 'resize' event. The handler function replots the plot during resize. Here, the plot targets's height and width must be specified as a percentage of the container and the container must be visible.

The event handler looks like:

    $('#resizable1').bind('resize', function(event, ui) {
        plot1.replot( { resetAxes: true } );
    });

The second plot uses an alternative sizing method that is more responsive in all browsers, especially IE. The differnece? First, the plot target is given a static height and width that will fit inside the resizable container. Then, instead of resizing dynamically with the container, the plots replot() method is called at the end of the resize. When resizing is done, the plot targets hieght and width are set to a percentage of the container's and then the replot method is called.

Also, an options object is passed into the replot method. It contains a single option, resetAxes, which, if true, resets all axes so the min, max, numberTicks and tickInterval are recalculated.

    $('#resizable2').bind('resizestop', function(event, ui) {
        $('#chart2').height($('#resizable2').height()*0.96);
        $('#chart2').width($('#resizable2').width()*0.96);
        plot2.replot({resetAxes:true});
    });

You can also pass in option objects to reset specific axes like:

    {resetAxes:['yaxis', 'y2axis']};
    
    or
    
    {resetAxes:{yaxis:true, y2axis:true}};