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

More »

 

Version 7.20
Version 7.20 (released in June 2026) is the latest version of RGraph and the major change in this version is an update to the default values of properties making for better looking charts without having to set any properties. Read more about this and other changes in the changelog.

Download »

 

Download
Get the latest version of RGraph (version 7.20, 9th June 2026) 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 »

 

Latest forum posts
These are the latest support forum posts that have been posted or updated.


16th June, Rachel
I have a question about the 3D Bar chart
12th June, Marco
Should I use SVG or canvas for the charts on my website?
9th June, Richard
New version of RGraph: version 7.20
3rd June, Patrick
Question about installing RGraph
1st June, Ouja
How do I add a click event to a bar in my Bar chart?


Support forum »

 

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 »

How to use DOM1 (.onclick, .onmousemove) events

Since the release of version 6.22 there's been an events property with which you can add events to your charts. This is now the preferred way to do it (though the on function still works perfectly well and is not being removed). There's an example of this below.

Previously, adding custom RGraph events was rather verbose - being modeled on the dom2 method of adding events. Now though you can use the older but more concise dom1 method. You can only add one dom1 event listener (which could do multiple things) but you can add both dom1 and dom2 style event listeners at the same time.

This example uses the draw custom event to add a highlight after-effect to the bars. The code to achieve this is shown below.

<script>
    bar = new RGraph.Bar({
        id: 'cvs',
        data: [[47,75],[32,74],[71,85],[25,19],[23,71],[81,59],[43,130],[23,20]],
        options: {
            colors: ['#494949','#35A0DA'],
            xaxisLabels: ['Alf','Bob','Carry','Dara','Edgar','Fliss','Gary','Harry'],
            yaxisLabelsCount: 3,
            marginLeft: 35,
            textSize: 14
        }
    });
    
    // Use the older DOM1 style of adding an event listener to the draw event
    bar.ondraw = function (obj)
    {
        var len = obj.coords.length;
        
        for (var i=0; i<len; ++i) {
            obj.path(
                'fs rgba(255,255,255,0.15) fr % % % %',
                obj.coords[i][0], obj.coords[i][1], obj.coords[i][2] / 2, obj.coords[i][3]
            );
        }
    }
    
    bar.draw();
</script>

The on() function

Because dom1 events don't work particularly well with chaining there's an on function which helps you to use the dom1 events and chaining. For example:

<script>
    bar = new RGraph.Bar({
        id: 'cvs',
        data: [5,8,9,6,4,5,5],
        options: {
            // ...
        }
    }).on('draw', function (obj)
    {
        // ...
    }).draw()
    
    bar.draw();
</script>

Using the events property

From version 6.22 there's now an events property that you can use to add events to your chart. More on the new events property here. This is an example of the tooltip event that you can use to create charts in tooltips.

<script>
    line = new RGraph.Line({
        id: 'cvs',
        data: [14,16,13,15,5,8,9,12],
        options: {
            labels: ['Luis','Kev','Jim','Harry','Hoolio','liss','Rhonda','Fred'],
            tooltips: '<canvas id="tooltip_canvas" width="300" height="100"></canvas>',
            tooltipsCss: {
                backgroundColor: 'white',
                color: 'black'
            },
            marginInner: 5,
            tickmarksStyle: 'endcircle',
            tickmarksSize: 7,
            textSize: 14,
            spline: true,
            events: {
                tooltip: function (obj)
                {
                    // This is the data for the tooltip bar chart
                    var tooltip_data = [[4,4,6],[4,7,5],[10,1,2],[5,5,5],[1,2,2],[4,2,2],[2,4,3],[6,4,2]];
                
                    // Get the visible tooltip
                    var tooltip = RGraph.Registry.get('tooltip');
                    var index   = tooltip.__index__;
                    
                    var bar = new RGraph.Bar({
                        id: 'tooltip_canvas',
                        data: tooltip_data[index],
                        options: {
                            marginLeft: 17,
                            marginRight: 5,
                            marginTop: 15,
                            xaxisLabels: ['Monday','Tuesday','Wednesday'],
                            backgroundGrid: false,
                            labelsAbovebar: true
                        }
                    }).draw();
                }
            }
        }
    }).draw();
</script>