Hello,
I'm trying to extract data from Google finance csv file using javasript.
however the csv file has 6 columns (Date,Open,High ,Low,Close,Volu me),
and i want only two columns (Date,Close) in array from it.
Following is the example of csv
I wrote following code according to http://bytes.com/topic/javascript/an...ascript-arrays
but i'm getting errors in the csvArray() method, 'undefined' is null or not an object.
regards,
Nitin Sawant
I'm trying to extract data from Google finance csv file using javasript.
however the csv file has 6 columns (Date,Open,High ,Low,Close,Volu me),
and i want only two columns (Date,Close) in array from it.
Following is the example of csv
Code:
Date,Open,High,Low,Close,Volume 5-May-09,399.98,405.00,397.25,402.99,2401096 4-May-09,398.17,402.40,394.79,401.98,3204843 1-May-09,395.03,397.59,391.55,393.69,2428611 30-Apr-09,395.76,403.75,394.80,395.97,4361069
but i'm getting errors in the csvArray() method, 'undefined' is null or not an object.
Code:
<html>
<head>
<title>- Another CSV parser -</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function loadData(){
$.get("http://finance.google.com/finance/historical",
{
q:'GOOG',
startdate:'May 1 2009',
enddate:'May 5 2009',
start:'225',
num:'25',
output:'csv'
},
function(data)
{
// Writing output into div
$("#csvDiv").html(data);
$("#csvDiv").hide();
ConvertToArray(data);
}
);
}
function csvArray(csv){
var i= 0;var A= csv.split(/\s*\n\s*/);
while(A[i++]) A[i]= A[i].split(/ *, */);
return A;
}
function ConvertToArray(data){
var myStr=$("#csvDiv").html();
var myArr=csvArray(myStr);
//ignore first 6 lines
var i=6;
for (i; i<myArr.length; i++) {
document.writeln(myArr[i]+'<br />');
}
}
</script>
</head>
<body>
<div id="csvDiv">
</div>
<script type="text/javascript">
loadData();
</script>
</body>
</html>
Nitin Sawant
Comment