A basic example of a CSV file and AJAX

This is a basic example of using a CSV file and AJAX. AJAX is used to request the CSV data from the server and it's returned in an array format. A chart is then created using it.

[No canvas support]

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>
    /**
    * Initiate 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.
    */
    RGraph.AJAX.getCSV('/getdata.html', drawGraph);

    /**
    * This is the AJAX callback function. The AJAX getCSV() function converts
    * the strings into numbers for you.
    */
    function drawGraph (csv)
    {
        
        var line = new RGraph.Line({
            id: 'cvs',
            data: csv,
            options: {
                hmargin: 0,
                linewidth: 2,
                xaxisLabels: ['Gary','Rachel','Neil','Martha','Kevin','Craig','John','Peter','Luis','Bert'],
                yaxisScaleMax: 100,
                marginLeft: 35
            }
        }).draw()
    }
</script>