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 »


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 »


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 »

Post-processing on a Bar chart

[no canvas support]

This Bar chart uses the custom RGraph draw event to add some highlighting to each bar.
There's an svg version of this chart in the download archive.

The highlighting is added using the draw event (which is triggered at the end of the draw function) so the coordinates of the bars are available.

The gradient is created using this bit of code, which uses an RGraph function for creating gradients easily:

obj.context.fillStyle = RGraph.linearGradient({
    object: obj,                  // The chart object
    x1: 0, y1: 0, x2: 0, y2: 250, // strartX, startY, endX, endY
    colors: [
        'rgba(255,255,255,.75)',  // Start color
        'rgba(255,255,255,0)'     // End color

The responsive function reduces the size of the text, turns off axes and the shadow and removes the css float from the canvas tag.

This goes in the documents header:
<script src="RGraph.common.core.js"></script>
<script src="RGraph.bar.js"></script>
Put this where you want the chart to show up:
<div style="float: left">
    <canvas id="cvs" width="600" height="250">[no canvas support]</canvas>
This is the code that generates the chart - it should be placed AFTER the canvas tag(s):
    // Create the bar chart just like a normal grouped bar chart
    new RGraph.Bar({
        id: 'cvs',
        data: [[47,75],[32,74],[71,85],[25,19],[23,71],[81,59],[43,130],[23,20]],
        options: {
            marginLeft: 50,
            colors: ['#494949','#35A0DA'],
            xaxisLabels: ['Alf','Bert','Craig','Dan','Edgar','Fred','Gary','Harry'],
            yaxisLabelsCount: 3,
            yaxisTickmarksCount: 3,
            backgroundGridHlinesCount: 3,
            backgroundGridVlines: false,
            backgroundGridBorder: false,
            colorsStroke: 'rgba(0,0,0,0)',
            shadowOffsety: -3,
            responsive: [
                {maxWidth: null,width:600,height:300,options: {textSize:14,marginInner: 5,shadow:true, xaxis: false,yaxis: false,}, parentCss: {'float': 'left',textAlign:'none'}},
                {maxWidth: 900, width:400,height:200,options: {textSize:10,marginInner: 2,shadow:false,xaxis: false,yaxis: false,}, parentCss: {'float': 'none',textAlign:'center'}}
    // Now use the draw event and the coordinates that were created when
    // the chart was drawn to add highlighting to the left side of each
    // bar. The highlighting is graduated from semi-opaque white at the top
    // to fully transparent white at the bottom.
    }).on('draw', function (obj)
        var len = obj.coords.length;

        for (var i=0; i<len; ++i) {

            // Get the coordinates for each bar - full height but only half
            // width.
            var x = obj.coords[i][0],
                y = obj.coords[i][1],
                w = obj.coords[i][2] / 2,
                h = obj.coords[i][3];

            // Create the gradient using an RGraph API function
            obj.context.fillStyle = RGraph.linearGradient({
                object: obj,
                x1: 0, y1: 0, x2: 0, y2: 250,
                colors: ['rgba(255,255,255,.75)','rgba(255,255,255,0)']
            // Draw the highlight rectangle