This is a basic example of using CSV and AJAX. AJAX is used to request the data and it is returned in CSV format. The JSON data is then evaluated and a chart created using it.
Note: In October 2013 a new CSV reader was added to RGraph. It makes reading CSV files much easier. You can read about the new CSV reader here.
This goes in the documents header:<script src="RGraph.common.core.js"></script> <script src="RGraph.line.js"></script>Put this where you want the chart to show up:
<canvas id="cvs" width="600" height="250">
[No canvas support]
</canvas>
This is the code that generates the chart:
<script>
/**
* Ths window.onload function initiates the AJAX request. The AJAX page is: http://www.rgraph.net/getdata.html
* If you view this in your browser you'll see that all it does is output a sequence of numbers.
*/
window.onload = function ()
{
RGraph.AJAX.getCSV('/getdata.html', drawGraph);
};
/**
* This is the AJAX callback function. The AJAX getCSV() converts the strings to numbers for you.
*/
function drawGraph (csv)
{
// Now draw the chart
var line = new RGraph.Line({
id: 'cvs',
data: csv,
options: {
textAccessible: true,
hmargin: 0,
linewidth: 2,
ymax: 100,
numxticks: 9,
gutterLeft: 35,
labels: ['Gary','Rachel','Neil','Martha','Kevin','Craig','John','Peter','Luis','Bert']
}
}).draw()
}
</script>