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 »

 

SQLite Editor for PHP
The SQLite Editor for PHP software is a tool which will help you and/or your users administer and maintain your SQLite databases. Built as a tool that you can easily provide to your users, there's no danger of them damaging your database.

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.


23rd June, Richard
The SQLite Editor for PHP admin tool is now available for you to download

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

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 »

The AJAX functions

Written by Richard Heyes, RGraph author, on 24th July 2018
This is a continuation of a spotlight series that highlights the various methods of getting data into RGraph. This time it's the turn of the AJAX functions. The AJAX functions in RGraph make it easy to get data from server-based sources, for example, web services.

Introduction

Since 2005 AJAX has been a popular choice for web developers. It can be used to good effect to get data from your server - be it initially when the page has just loaded or after the page has loaded (for example, to facilitate periodic updates).

You might want to do this to make it easier to integrate with legacy or pre-existing server-based scripting. Or it could be an easier way to handle migration if that's what you're doing.

An example use-case would be when you have a chart - perhaps a Line chart that you want to update with new data.

What you could do is simply refresh the page. This however might have other consequences that you'd rather not have to deal with.

Also if your page is weighty then bandwidth or page load speed might be a concern that you'd prefer not to have.

What AJAX functions are available?

The canvas AJAX functions that are available are documented on the canvas AJAX documentation page and the SVG AJAX functions are documented on the SVG AJAX documentation page . They're very similar in their working though.

Example code

The following URL is used by several of the demos to produce charts

And the code to make a chart is as follows - making use of the getString() function. Remember that when using this function you'll probably need to convert any numbers from strings (which is what they are initially) to numbers.

<script>
    // This initiates the AJAX call to fetch the sample.csv file and runs
    // the function when it has completed.
    RGraph.SVG.AJAX.getString('/sample.csv', function (data)
    {
        // Convert the data from the file into a usable format. Notice that
        // the last bit (the forEach() loop) converts all of the numbers from strings
        // into real numbers. It's important to do this.
        data = data.split(/\r?\n/);
        data = data[0].split(/,/).slice(1);
        data.forEach(function (v, k, arr)
        {
            arr[k] = parseInt(v);
        });

        // Create and display the chart
        new RGraph.SVG.Line({
            id: 'cc',
            data: data,
            options: {
                title: 'A chart demonstrating the AJAX functions',
                titleY: '-10',
                xaxisLabels: ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'],
                textSize: 20,
                marginTop: 50,
                linewidth: 5
            }
        }).draw();
    });
</script>

Further reading

Read the documentation for the AJAX functions. There's a set for both the canvas and SVG chart types.