The exec function
The exec function can be used to run a function at the start or end of the configuration - depending on where you place the call - instead of waiting for an event to be triggered.
The exec()
function can be used when you want a
function to run immediately in the configuration (as opposed to the
beforedraw
and draw
events which occur when
you call the draw()
function.
<script> bar = new RGraph.Bar({ id: 'cvs', data: [2,2,2,1,2,3,2,3,4], options: { yaxisLabels: false, colors: ['red','pink','blue','yellow','#0f0','gray','red','green','black'], colorsSequential: true, marginLeft: 50 } }).draw().exec(function (obj) { alert('In the exec() function'); }); </script>It can run either BEFORE the
draw()
function or AFTER based on whether you put the function before or after
the draw()
call. Here's an example of it being used BEFORE the draw function call
(so it's similar to the beforedraw
event - but only runs once:
<script>
bar = new RGraph.Bar({
id: 'cvs',
data: [2,2,2,1,2,3,2,3,4],
options: {
yaxisLabels: false,
colors: ['red','pink','blue','yellow','#0f0','gray','red','green','black'],
colorsSequential: true,
marginLeft: 50
}
// The exec() function is before the draw()
call so in effect it would be very
// similar to a beforefirstdraw
event - but that event doesn't exist.
}).exec(function ()
{
alert('The chart has not been drawn yet.');
}).draw();
</script>
And here is an example of using the exec()
function AFTER the draw()
function
call. Remember that the exec()
function is only run ONCE - so it's very much
like the firstdraw
event that you can use. In fact the difference
may be just syntax.
<script>
bar = new RGraph.Bar({
id: 'cvs',
data: [2,2,2,1,2,3,2,3,4],
options: {
yaxisLabels: false,
colors: ['red','pink','blue','yellow','#0f0','gray','red','green','black'],
colorsSequential: true,
marginLeft: 50
}
}).draw()
// The exec()
function is AFTER the draw()
call so in effect it more or less
// is the same as the firstdraw
event.
.exec(function ()
{
alert('The chart has been drawn at this point');
});
</script>