2011-09-11 8 views
-2

私はhighchartsjQueryで2番目のCSVを読み込むにはどうすればよいですか?

$(function() { 
     $.get('trades.csv', function(csv, state, xhr) { 

      // inconsistency 
      if (typeof csv != 'string') { 
       csv = xhr.responseText; 
      } 

      // parse the CSV trades 
      var trades = [], header, comment = /^#/, x; 

      $.each(csv.split('\n'), function(i, line){ 
       if (!comment.test(line)) { 
        if (!header) { 
         header = line; 
        } 
        else { 
         var point = line.split(';'), 
          date = point[0].split('-'); 
          time = point[1].split(':'); 

         if (point.length > 1) { 
          x = Date.UTC(date[2], date[1] - 1, date[0], time[2], time[1], time[0]); 

          trades.push([ 
           x, // time 
           parseFloat(point[2]) // close 
          ]); 
         } 
        } 
       } 

      }); 

から次のコードスニペットを持っているが、私は適切で再び$に.getを貼り付けて試してみました... =私は VARスプレッドに二spreads.csvをロードしたい

を仮定しますページはもはや読み込まれません。 2番目のCSVをロードするための正しい構文は何ですか?

+1

エラーコンソールにはどのようなエラーがありますか?どの時点で2番目のファイルをロードしますか? –

答えて

1
function getCsv(file_name, array_holder){ 
    $.get(file_name, function(csv, state, xhr) { 

     // inconsistency 
     if (typeof csv != 'string') { 
      csv = xhr.responseText; 
     } 

     // parse the CSV trades 
     var header, comment = /^#/, x; 

     $.each(csv.split('\n'), function(i, line){ 
      if (!comment.test(line)) { 
       if (!header) { 
        header = line; 
       } 
       else { 
        var point = line.split(';'), 
         date = point[0].split('-'), 
         time = point[1].split(':'); 

        if (point.length > 1) { 
         x = Date.UTC(date[2], date[1] - 1, date[0], time[2], time[1], time[0]); 

         array_holder.push([ 
          x, // time 
          parseFloat(point[2]) // close 
         ]); 
        } 
       } 
      } 

     }); 
    }); 
} 

$(function() { 
    var trades = [], 
     spreads = []; 
    getCsv('trades.csv', trades); 
    getCsv('spreads.csv', spreads); 

}); 
関連する問題