MENU
.net Powerful JavaScript charts
About
RGraph is a JavaScript charts library based on HTML5 SVG and canvas. RGraph is mature (over 17 years old) and has a wealth of features making it an ideal choice to use for showing charts on your website.

More »

 

Version 7.01 released
Version 7.01 (released in October 2025) is the latest version of RGraph and now includes a new tree structure object. The accompanying Treemenu object can then turn the object into a fully dynamic tree menu. You can read the API documentation for the tree on the main API documentation page and see an example of the Treemenu feature by following this link...

More »

 

New HTML datagrid
In the April 2025 (v6.21) release a new datagrid object was added. This makes it easy to add static or dynamic data tables to your pages. It can be used whether you use the canvas or SVG libraries or entirely standalone.

Read more »

 

Download
Get the latest version of RGraph (version 7.01, 8th October 2025) from the download page. You can read the changelog here. There's also older versions available, minified files and links to cdnjs.com hosted libraries.

Download »

 

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

More »

Custom events

Adding events using the events property in the main configuration is now the preferred method. Click on the link for more information.

Introduction to custom events

Custom events allow you to easily interact with and extend RGraph for your own purposes. The list of available events is below, as is an example of how to make use of them. Event handler functions (ie your functions) are passed a single parameter - the chart object. With this, you can get references to the canvas and context. There's an example of this below.

<script>
    line = new RGraph.Line({
        id: 'cvs',
        data: [45,12,16,18,44,54,23,21,56],
        options: {
            xaxisLabels: ['Fred', 'Barney', 'Jay', 'Pete', 'Frank', 'Bob', 'Ted', 'Lou', 'Kev'],
            tooltips: ['Fred', 'Barney', 'Jay', 'Pete', 'Frank', 'Bob', 'Ted', 'Lou', 'Kev'],
            marginInner: 5,
            tickmarksStyle: 'dot',

            
            // As of version 6.22, the events property is now the prferred way to install events
            // on your charts. Prior to this you would need to use the on() function or resort
            // to DOM1 style events.
            events: {
                tooltip: function myFunc(obj)
                {
                    var id      = obj.id;
                    var canvas  = obj.canvas;
                    var context = obj.context;
            
                    alert('This alert was triggered by the custom tooltip event');
                }
            }
        }
    }).draw();
</script>

Available events

Name: beforetooltip
Description: 
The beforetooltip fires just before a tooltip is created and shown.
Name: tooltip
Description: 
The tooltip event fires just after a tooltip has been created and shown. Note that effect timers may make it look like that the event fires before the tooltip appears.
Name: beforecontextmenu
Description: 
The beforecontextmenu event fires just before the contextmenu is shown.
Name: contextmenu
Description: 
The contextmenu event fires when the contextmenu is shown.
Name: beforedraw
Description: 
This event fires before the draw method runs. It can fire multiple times (eg when a tooltip is hidden).
Name: firstdraw
Description: 
This event fires the first (and only the first) time that the chart is drawn (after the draw is complete, but before the draw event fires).
Name: draw
Description: 
This event fires after the draw method has run. It can fire multiple times (eg when a tooltip is hidden).
Name: modaldialog
Description: 
The modaldialog event fires when the ModalDialog that comes with RGraph is shown. This event is added slightly differently to other events:
ModalDialog.addCustomEventListener('modaldialog', function () {alert('Hello world!');});
Name: adjustbegin
Description: 
This event fires when adjusting begins.
Name: adjust
Description: 
This event fires during adjusting.
Name: adjustend
Description: 
This event fires when adjusting ends. Much like the mouseup event.
Name: annotatebegin
Description: 
This event fires when annotating begins.
Name: annotate
Description: 
This event fires during annotating - much like the mousemove event.
Name: annotateend
Description: 
This event fires when annotating ends.
Name: annotatecolor
Description: 
This event fires when the annotate color is changed via the mini-palette.
Name: annotateclear
Description: 
This event fires when the annotations are cleared using the api function RGraph.clearAnnotations
Name: beforeclear
Description: 
This event fires just before the canvas is cleared using the api function RGraph.clear
Name: clear
Description: 
This event fires when the canvas is cleared using the api function RGraph.clear
Name: crosshairs
Description: 
This event fires when the canvas is cleared using the api function RGraph.clear.
Name: beforeinteractivekey
Description: 
This event fires before the interactive key has triggered and is about to highlight the chart. You can get the index of the key element by: obj.get('keyInteractiveIndex');
Name: afterinteractivekey
Description: 
This event fires after the interactive key has triggered and has highlighted the chart. You can get the index of the key element by: obj.get('keyInteractiveIndex');
Name: beforebackground
Description: 
This event fires before the background is drawn in charts that use a background (ie Bar charts Gantt charts Horizontal Bar charts Line charts Scatter charts Waterfall charts drawing api Background).
Name: background
Description: 
This event fires after the background is drawn in charts that use a background (ie Bar charts Gantt charts Horizontal Bar charts Line charts Scatter charts Waterfall charts drawing api Background).

Adding DOM2 events

Instead of DOM1 events you may want to use the older DOM2 style method of adding event listeners. These can facilitate the addition of multiple event listeners compared to their DOM1 cousins. They are installed like this:

<script>
    line = new RGraph.Line({
        id: 'cvs',
        data: [45,12,16,18,44,54,23,21,56],
        options: {
            xaxisLabels: ['Fred', 'Barney', 'Jay', 'Pete', 'Frank', 'Bob', 'Ted', 'Lou', 'Kev'],
            tooltips: ['Fred', 'Barney', 'Jay', 'Pete', 'Frank', 'Bob', 'Ted', 'Lou', 'Kev'],
            marginInner: 5,
            tickmarksStyle: 'dot'
        }
    }).draw()

    
    function myFunc (obj)
    {
        // ...
    }
    RGraph.addCustomEventListener(line, 'ontooltip', myFunc);
</script>

Removing DOM2 events

In the case that you need to remove RGraph event listeners, there are a few ways that you can do it. The API function RGraph.removeCustomEventListener(obj, id) can be used to remove a single event listener. This function takes the chart object and the numerical ID (returned by RGraph.addCustomEventListener) as its arguments.

There's also the RGraph.removeAllCustomEventListeners, for easily removing all of the pertinent event listeners. This function can either take no arguments at all, in which case ALL event listeners for ALL objects are removed. Or it can also take a canvas id (the same id that you pass to the constructor), in which case the removal will be limited to that canvas.

Note that the RGraph.removeAllCustomEventListeners function only applies to events that are installed using the DOM2 style. DOM1 event listeners are unaffected.

Adding events within the main configuration

From version 6.22 adding events using the inline events configuration property is now the preferred way to add your event listeners. The on method is still part of RGraph and still works exactly the same - so nothing should change with your existing charts. The example from above could be modified to the following:

<script>
    line = new RGraph.Line({
        id: 'cvs',
        data: [45,12,16,18,44,54,23,21,56],
        options: {
            xaxisLabels: ['Fred', 'Barney', 'Jay', 'Pete', 'Frank', 'Bob', 'Ted', 'Lou', 'Kev'],
            tooltips: ['Fred', 'Barney', 'Jay', 'Pete', 'Frank', 'Bob', 'Ted', 'Lou', 'Kev'],
            marginInner: 5,
            tickmarksStyle: 'dot',
    
            //
            // This is the installation of the event listeners.
            // They're installed using the up-to-date method of
            // using the events property in the main configuration.
            //
            events: {
                beforedraw: function (obj) {alert('The chart is about to be drawn!');},
                draw:       function (obj) {alert('The chart has been drawn!');}
                tooltip:    function (obj) {alert('This alert was triggered by the custom tooltip event');}
            }
        }
    }).draw();
</script>