A grouped SVG Bar chart using the CSV reader


Note: For browser security reasons the AJAX demos don't work offline (this demo is using the CSV reader option that reads data that's embedded in the page itself). You can view the demos on the RGraph website here: http://www.rgraph.net/demos/index.html#svg and this demo is available here: http://www.rgraph.net/demos/svg-bar-csv2.html

This goes in the documents header:
<script src="RGraph.svg.common.core.js"></script>
<script src="RGraph.svg.common.ajax.js"></script>
<script src="RGraph.svg.common.csv.js"></script>
<script src="RGraph.svg.bar.js"></script>
Put this where you want the chart to show up:
<div style="width: 750px; height: 300px" id="chart-container"></div>
    [No canvas support]
</div>
This is the code that generates the chart:
<script>
    new RGraph.CSV('/sample.csv', function (csv)
    {
        var numrows = csv.numrows,
            rows    = [],
            row     = [],
            labels  = [];
    
        for (var i=0; i<numrows; ++i) {
            
            var row   = csv.getRow(i, 1).slice(0,3);
            var label = csv.getRow(i).slice(0,1)[0];

            rows.push(row);
            labels.push(label);
        }

        new RGraph.SVG.Bar({
            id: "chart-container",
            data: rows,
            options: {
                gutterLeft: 50,
                unitsPost: 'k',
                colors: ['red','green', 'blue'],
                hmargin: 10,
                noaxes: true,
                backgroundGridBorder: false,
                backgroundGridVlines: false,
                //grouping: 'grouped',
                xaxisLabels: labels
            }
        }).grow();
    });
</script>

« Back