2011-01-19 74 views
0

我有一個CSV文件:Highchart,CSV和48小時時間軸,顯示過去48個時數據

2011-01-11, 0:00, 4 
2011-01-11, 0:05, 2 
2011-01-11, 0:10, 6 
2011-01-11, 0:15, 8 
... 
2011-01-12, 0:00, 4 
2011-01-12, 0:05, 2 
... 
2011-01-13, 20:00, 4 
2011-01-13, 20:05, 2 
... 

什麼是最好的做法,只顯示最近48時數據?

這裏是CSV解析器:

$.get('data.csv', function(data) { 
       // Split the lines 
       var lines = data.split('\n'); 
       $.each(lines, function(lineNo, line) { 
        var items = line.split(','); 

       // header line containes categories 
       if (lineNo == 0) { 
        $.each(items, function(itemNo, item) { 
         if (itemNo > 0) options.xAxis.categories.push(item); 
        }); 
       } 

       // the rest of the lines contain data with their name in the first position 
       else { 
        var series = { 
         data: [] 
        }; 
        $.each(items, function(itemNo, item) { 
         if (itemNo == 0) { 
          series.name = item; 
         } else { 
          series.data.push(parseFloat(item)); 
         } 
        }); 

        options.series.push(series); 

       } 

      }); 

是否修改此解析器僅加載從CSV持續288線(24小時制數據)的好辦法?如果是的話,我該怎麼做?

回答

1

你的來源是有點混亂,但它看起來像你可以只slice斷行你想:

var lines = data.split('\n').slice(-288); 
相關問題