2014-01-24 37 views
1

我不是很熟練的JavaScript,但我已經設法湊齊這個代碼來繪製我的數據,但我得到一個錯誤#15(Highcharts希望數據排序)。我已經搜遍了,但我需要幫助來解決在我的具體情況。如何解決highstocks錯誤#15

這裏是我的代碼以.csv數據的樣本:

 $(document).ready(function() { 


     var options = { 

      chart: { 
       renderTo: 'container', 
       type: 'line' 
      }, 

      title: { 
       text: 'Temperature' 
      }, 

      xAxis: { 
       categories: [] 
      }, 

      yAxis: { 
       title: { 
        text: 'Temp' 
       } 
      }, 
      series: [] 
     }; 

    /* 
    Data Series in .csv file are in columns, e.g.: 

    1/24/2014 12:00:29 AM,74.64 
    1/24/2014 12:01:29 AM,74.75 
    1/24/2014 12:02:29 AM,74.86 
    1/24/2014 12:03:29 AM,74.98 
    1/24/2014 12:04:29 AM,74.98 
    1/24/2014 12:05:29 AM,75.09 
    1/24/2014 12:06:29 AM,75.09 

    */ 

     $.get('temp2.log', function(data) { 

      var lines = data.split('\n'); 

      lines = lines.map(function(line) { 

       var data = line.split(','); 

       sections = data[0].split(' '); 
       section1 = sections[0].split('/'); 

       mm = parseInt(section1[0]-1); 
       dd = parseInt(section1[1]); 
       yyyy = parseInt(section1[2]); 

       section2 = sections[1].split(':'); 

       hh = parseInt(section2[0]); 
       mi = parseInt(section2[1]); 
       ss = parseInt(section2[2]); 

       section3 = sections[2]; 

       if(section3 == 'AM') hh = hh; 
       if(section3 == 'PM') hh = hh + 12; 

       formatDate = Date.UTC(yyyy, mm , dd, hh, mi, ss); 

       /* console.log(formatDate); */ 

       data[0] = formatDate; 
       data[1] = parseFloat(data[1]); 

       return data; 

       }); 


      var series = { 
       data: lines, 
       name: 'temp' 
      }; 

      options.series.push(series); 

       var chart = new Highcharts.StockChart(options); 
     }); 


    }); 
+0

您確定'temp2.​​log'的格式正確嗎?它是否包含標題或前導/尾隨換行符?我試圖用jsFiddle複製你的問題,但它工作正常:http://jsfiddle.net/6ffmn/ – Mark

+0

你的系列對象如何在這行看起來像這樣options.series.push(series); ? –

回答

0

試着改變你的代碼

var lines = data.split('\n');

var lines = data.split(/\r\n|\n/);

您的問題它可能與carria有關ge在csv文件中返回