Display line chart by loading data from a text file from server

227 views
Skip to first unread message

Arif

unread,
Mar 28, 2012, 9:27:17 PM3/28/12
to Google Visualization API
Hello,
I am new to Google Visualization API. Here is something I need some
help on:
I have a text file stored in my server (I am using XAMPP, i.e. apache
as the server). The text file is simple - just one integer per line,
like this:
2000
1794
1585
1393
1195
1044
891
771
662
570

I need to "read" the file (which is in a specified directory), then
display a line chart from the data read.
I was trying to feed an array of data to
google.visualization.DataTable() but failed.

Any working example would be greatly appreciated.

asgallant

unread,
Mar 29, 2012, 10:48:28 AM3/29/12
to google-visua...@googlegroups.com
Generally, each data point requires (x,y) coordinates for the chart, but assuming a) you have successfully fetched the data from the file and b) you can get by with just incrementing the 'x' values for each point, you could try something like this:

function drawChart ({
    // assumes "file" has the contents of the data file
    var dataArray file.split('\n');
    var data new google.visualization.DataTable();
    data.addColumn('number''X');
    data.addColumn('number''Y');
    
    for (var 0dataArray.lengthi++{
        data.addRow([idataArray[i]]);
    }
    
    // create and draw chart
Reply all
Reply to author
Forward
0 new messages