Resizing your charts
RGraph has the facility to allow you to resize your charts. This is new as of 10th April 2010. Because of the
numerous events it has to install code on, it is possible that it may not work well with another dynamic feature that you may
want to use. The context menu does though, and the example shows tooltips. and resizing.
All you need to do to enable it is set chart.resizable to true. There are certain caveats that you should be aware of though:
-
Charts can only be enlarged down and to the right, so you will get better results if your chart is not placed at the
right of the page.
-
The minimum you can resize your charts to is 50% of the original chart width/height.
-
Note: Resizing can change the layout of your page (reflows). As such you will need to be careful when laying out your
page, and you may need to experiment with things like CSS float:, width, height etc so that the effect is either not apparent
or is minimal.
-
If your canvas is nested within a table, resizing can result in very minor (1-2px) positioning changes. These
can be mitigated by turning off table borders, setting the cellspacing to 0 and also setting the cellpadding to 0.
-
In the above example, the Line charts chart.hmargin setting has to be recalculated when the canvas is resized
using the custom onresizebeforedraw RGraph event. This allows the Line chart to be positioned correctly on top
of the Bar chart when the canvas is resized. The relevant code for doing this is:
/**
* This recalculates the Line chart hmargin when the chart is resized
*/
function myOnresizebeforedraw (obj)
{
var gutterLeft = obj.Get('chart.gutter.left');
var gutterRight = obj.Get('chart.gutter.right');
obj.Set('chart.hmargin', (obj.canvas.width - gutterLeft - gutterRight) / (obj.original_data[0].length * 2));
}
RGraph.AddCustomEventListener(myLine, 'onresizebeforedraw', myOnresizebeforedraw);