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
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?
AJAX functions
The RGraph SVG libraries incorporate ajax functions that make it easy for you to fetch data from your server and then use it to create your charts. You can use them by simply including the file RGraph.svg.common.ajax.js in your page and then use the functions like the following example code shows.
See also:
There's also a dedicated CSV reader that fetches data via ajax.
The CSV reader is documented here.
<script>
RGraph.SVG.AJAX.getJSON('/getdata.html?json', function (json)
{
var bar = new RGraph.SVG.Bar({
id: 'chart-container',
data: json.data,
options: {
xaxisLabels: json.labels,
marginInner: 5,
yaxisScaleMax: 100,
marginLeft: 50
}
}).draw();
});
</script>
The available functions can just fetch the desired resource or they can go further, such as the getJSON function which doesn't return the string that the server provides; it returns a usable javascript object for you. Here are the functions:
RGraph.SVG.AJAX('/get.html', function (text)
{
// Your code goes here
});
RGraph.SVG.AJAX.post('/post.html', {forename: 'Jane', surname: 'Hayford'}, function (text)
{
// Your code goes here
});
RGraph.SVG.AJAX.getNumber('/number.html', function (num)
{
// Your code goes here
});
RGraph.SVG.AJAX.getString('/string.html', function (str)
{
// Your code goes here
});
RGraph.SVG.AJAX.getJSON('/json.html', function (json)
{
// Your code goes here
});
RGraph.SVG.AJAX.getCSV('/csv.html', function (csv)
{
// Your code goes here
});
Unless specified otherwise, the field separator is a comma
and the line separator is a newline (\n) which is optionally preceded by a carriage return (\ r).