About
RGraph is a JavaScript charts library based on HTML5 SVG and canvas. RGraph is mature (over 15 years old) and has a wealth of features making it an ideal choice to show charts on your website.

More »

 

License
RGraph can be used for free under the GPL or if that doesn't suit your situation there's an inexpensive (£99) commercial license available.

More »

 

Download
Get the latest version of RGraph (version 6.17) from the download page. There's also older versions available, minified files and links to cdnjs.com hosted libraries.

More »

The exec function

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>