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.

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?
8th May, Anthony Kuma
Does the SVG Line chart have outofbounds functionality?


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 »

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>
</div>
This is the code that generates the chart - it should be placed AFTER the canvas tag(s):
<script>
    // 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,
            backgroundGridHlinesCount: 3,
            responsive: [
                {maxWidth: null,width:600,height:300,options: {textSize:14,marginInner: 5}, parentCss: {'float': 'right',textAlign:'none'}},
                {maxWidth: 900, width:500,height:250,options: {textSize:10,marginInner: 2}, 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 fully opaque white at the
            // top to semi-transparent white at the bottom.
            events: {
                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: 35, x2: 0, y2: 250,
                            colors: ['white','rgba(255,255,255,.25)']
                        });
                        
                        // Draw the highlight rectangle
                        obj.context.fillRect(x,y,w,h)
                    }
                }
            }
        }
    
    }).draw();
</script>