If you want to load a text file like that as the source of your data, you
need to use AJAX to pull the data into browser. Many javascript libraries
offer AJAX tools to help you do this, here's an example using jQuery:
function drawChart () {
$.ajax({
url: '/path/to/mydata.txt',
type: 'text',
success: function (txt) {
var dataArray = [['column 1 label', 'column 2 label']];
var txtArray = txt.split('\n');
for (var i = 0; i < txtArray.length; i++) {
// splits the text row by whitespace
// assumes that the only whitespace in the row separates
column 1 from column 2
var tmpData = txtArray[i].split(/\s+/);
// insert the data into the data array
// parsing the numbers as integers
// you can use parseFloat instead, if you need floating
point numbers
dataArray.push(tmpData[0], parseInt(tempData[1]));
}
var data = google.visualization.arrayToDataTable(dataArray);
var chart = new
google.visualization.LineChart(document.querySelector('#chart_div'));
chart.draw(data, {
// chart options
});
}
});
}
google.load('visualization', '1', {packages:['corechart'], callback:
drawChart});
On Monday, February 3, 2014 4:03:26 AM UTC-5, Yoonchung Ock wrote:
>
> I want to insert data from my server from text file for google chart. line
> chart.
>
> the text file is very simple...just two columns..
>
> ex.
> A 12
> B 123
> C 32
> D 32
>
> How can I read data from that text file and draw chart on web page with
> that data?
> Help me please..
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.