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 use for showing charts on your website.

More »


Get the latest version of RGraph (version 6.18, 1st June 2024) 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.

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 »

Using query string data


If you're passing data around via the query string that's going to be displayed on your charts then RGraph has a set of functions that will make this much easier for you.

These functions take the name of the query string parameter that you want and return the value to you in the desired format which can be a number, a string, a json object or a javascript array depending on your data and which function you use.

The available functions

The available functions are:


This function will return a single number to you. The returned value is a Number type (remember the query string starts off as a string). An example of using it is:
    // URL: example.html?myNumber=-67.9
    var num = RGraph.GET.number('myNumber');


This function will return a string (text) to you. Naturally, the type of the variable will be String. An example of using it is:
    // URL: example.html?myString=someRandomText
    var str = RGraph.GET.string('myString');
Note that you may need to encode the URL when you generate it if it has non-URL-safe characters in it.


This function will return an array of data to you. You can use it to get whole datasets from the query string. An example of using it is:
    //    URL: example.html?myArray=5,8,4,6,3,5,8
    // or URL: example.html?myArray=[5,8,4,6,3,5,8]
    // or URL: example.html?myArray=5|8|4|6|3|5|8
    // Get a normal, comma-separated list (with or without enclosing square brackets)
    var arr = RGraph.GET.array('myArray');
    // Or using the second parameter to specify the separator character
    var arr = RGraph.GET.array('myArray', '|');


This is undoubtedly the most useful of all these functions. It fetches an entire json object (a regular javascript object) from the URL. The advantage of passing an object around is that you can pass multiple bits of information at the same time - for example, both the data and also the labels. An example of using it is:
    // URL: example.html?myObject={"data":[5,4,3],"labels":["John","Luis","Bob"]}
    // Get the object from the URL
    var json = RGraph.GET.json('myObject');
    // And then in your chart configuration you can use json.data and json.labels
    // like in the example code below
Note 1

The json parsing function in javascript is strict in it's interpretation of json - so your strings must be enclosed by double-quotes - not single-quotes. So this would work:

But this would not (single-quotes are not allowed):
Note 2

Also note that you should try to avoid spaces in json where they're not needed. This avoids you seeing lots of %20 encodings in the URL.

Note 3

If you're hoping to get pages indexed by Google, they've previously advised that you shouldn't use certain characters in URLs (for example: { } , [ ]). So this means that you shouldn't use json in these URLs.

An example

This is an example of using the RGraph.GET.json function (because it's the most versatile). It uses a URL like this:

    json = RGraph.GET.json('json');

    if(json) {
        new RGraph.Bar({
            id: 'cvs',
            data: json.data,
            options: {
                xaxisLabels: json.labels,
                xaxis: false,
                yaxis: false,
                backgroundGridVlines: false,
                backgroundGridBorder: false,
                responsive: [
                    {maxWidth: null, width: 700, height: 300, options:{textSize: 16, marginInner: 20}},
                    {maxWidth: 750, width: 400, height: 200, options:{textSize: 11, marginInner: 5}}