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 »

HOWTO: Create sparklines

A previous request has been for inline plus/minus charts - much like sparklines. Both of these are possible by using the configuration options available to make the chart appear as desired. The main thing is to use a smaller canvas size to make the chart fit inline with your text.

Inline Bar charts

Here the colors are defined by looping through the data beforehand to determine whether a value is positive or negative. When this is ascertained the color can be set appropriately and also the colorsSequential option is set to true. This is an example of an inline Bar chart:

<canvas id="cvs" width="50" height="20" style="background-color: white">[No canvas support]</canvas>

<script>
    data = [10,9,8,-8,-9,-10];
    colors = [];

    // Create the colors
    for (var i=0; i<data.length; ++i) {
        colors.push(data[i] > 0 ? '#0f0' : 'red');
    }
        
    new RGraph.Bar({
        id: 'cvs',
        data: data,
        options: {
            xaxisPosition: 'center',
            yaxisScale: false,
            yaxis: false,
            backgroundGrid: false,
            colors: colors,
            colorsSequential: true,
            marginLeft: 2,
            marginRight: 2,
            marginTop: 2,
            marginBottom: 2,
            colorsStroke: 'rgba(0,0,0,0)',
            marginInner: 1,
            xaxisTickmarksLength: 0
        }
    }).draw();
</script>

Inline Line charts (sparklines)

With sparklines the process is much the same except without the loop for the colors.

<canvas id="cvs" width="50" height="20">[No canvas support]</canvas>

<script>
    new RGraph.Line({
        id: 'cvs',
        data: [4,5,3,4,2,3,5,4,5,4,3,5,3],
        options: {
            marginLeft: 1,
            marginRight: 1,
            marginTop: 1,
            marginBottom: 1,
            backgroundGrid: false,
            xaxis: false,
            yaxis: false,
            linewidth: 1,
            tickmarksStyle: null,
            yaxisScaleMax: 10,
            yaxisScale: false,
            shadow: false
        }
    }).draw();
</script>

Taking it further

One option if you're finding the charts too small, or you wish to enlarge them when clicked is to add an anchor (link) around the canvas so that when clicked a ModalDialog is shown with a larger version of the chart - a detail view if you like. There's a HOWTO document about using the ModalDialog here.