A description of the new AJAX functions

The AJAX functions in RGraph will help you easily get data from your server (from AJAX services for example). The SVG libraries have their own set of AJAX functions which are documented here.

RGraph now has new AJAX functions that make it much easier to make AJAX requests without having to be concerned about what the response is (string, number, object etc).

Previously, because the response to an AJAX request is a string, you had to convert it into a usable form (such as a number or an array).

Now though there are helper functions that will automatically do the conversion for you. The AJAX functions that are available to you now consist of:

The first three functions are pretty clear. The getCSV() function gets a comma separated set of numbers and converts it to an array for you so that you can use it as an RGraph dataset.

It doesn't support multi line files - it only gets a single line of CSV data. If you want multi-line support you'll need to use the CSV reader .

The getJSON() function gets the URL that you give it and treats the response as JSON (ie it runs the eval() function on the response).

Using JSON means that you can get multiple datasets and/or labels or other information in your response.

The POST function allows you to make POST requests - sending data back to the server. The data argument should be a JavaScript object of key/value pairs that should be sent to the server as POST data. The data is encoded for you.

There are straight-forward examples of the AJAX functions in the basic examples in the download archive

window.onload = (function ()
    RGraph.AJAX.getJSON('/getdata.html?json', function (json)
        new RGraph.Bar({
            id: 'cvs',
            data: json.data,
            options: {
                marginLeft: 50,
                hmargin: 10,
                tickmarksStyle: 'endcircle',
                linewidth: 2,
                xaxisLabels: json.labels

* As of October 2013 there's now a dedicated CSV reader (that also fetches the CSV via AJAX) * part of RGraph.