2011-01-19 3 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 시간 데이터를 표시하는 것입니까?

$.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 시간 데이터) 마지막으로이 파서를 수정할 수있는 좋은 방법입니다 : 여기

은 CSV 파서입니까? 그렇다면 어떻게 할 수 있습니까?

답변

1

귀하의 소스는 약간 뒤죽박죽이지만, 그냥 slice 라인 떨어져 당신이 원하는 수있는 다음과 같습니다

var lines = data.split('\n').slice(-288); 
관련 문제