2015-01-15 29 views
0

我想從ajax調用中獲取highcharts中的系列。但由於某種原因,它不工作。我沒有得到圖表中填充的數據。請任何人都可以幫助我。如何從ajax將數據加載到highcharts?

$(document).ready(function() { 

     $('#exercise').submit(function(e) { 
      var form = $(e.target); 
      e.preventDefault(); 

      $.ajax({ 
       type: form.attr('method'), 
       url: form.attr('action'), 
       dataType: 'json', 
       data: form.serialize(), 
       success : function(data){ 
        alert("parse"); 
        alert(data); 
        chart4(data); 

       }, 
       error : function(){ 
        alert("Exercise Error!"); 
       } 
      }); 
     }); 
    }); 

這是我的Ajax調用

unction chart4(data){ 
 
Highcharts.setOptions({ 
 
\t \t   
 
\t \t  }); 
 
\t \t \t alert("HIT"); 
 
\t \t \t \t var chart = new Highcharts.Chart({ 
 
\t \t \t \t \t \t chart: { 
 
\t \t \t \t \t \t \t renderTo: 'container', 
 
\t \t \t \t \t \t \t defaultSeriesType: 'column', 
 
\t \t \t \t \t \t \t margin: [50, 150, 60, 80] 
 
\t \t \t \t \t \t }, 
 
\t \t \t \t \t \t title: { 
 
\t \t \t \t \t \t \t text: 'Exercise', 
 
\t \t \t \t \t \t \t style: { 
 
\t \t \t \t \t \t \t \t margin: '10px 100px 0 0' // center it 
 
\t \t \t \t \t \t \t } 
 
\t \t \t \t \t \t }, 
 
\t \t \t \t \t  xAxis: { 
 
\t \t \t \t \t    type: 'datetime', 
 
\t \t \t \t \t    dateTimeLabelFormats: { 
 
\t \t \t \t \t     month: '%e. %b', 
 
\t \t \t \t \t     year: '%b' 
 
\t \t \t \t \t    }, 
 
\t \t \t \t \t    
 
\t \t \t \t \t    
 
\t \t \t \t \t   }, 
 
\t \t \t \t \t   yAxis: { 
 
\t \t \t \t \t    min: 0, 
 
\t \t \t \t \t    title: { 
 
\t \t \t \t \t     text: 'Minutes' 
 
\t \t \t \t \t    } 
 
\t \t \t \t \t   }, 
 
\t \t \t \t \t   tooltip: { 
 
\t \t \t \t \t    headerFormat: '<span style="font-size:10px">{point.key}</span><table>', 
 
\t \t \t \t \t    pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + 
 
\t \t \t \t \t     '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>', 
 
\t \t \t \t \t    footerFormat: '</table>', 
 
\t \t \t \t \t    shared: true, 
 
\t \t \t \t \t    useHTML: true 
 
\t \t \t \t \t   }, 
 
\t \t \t \t \t   plotOptions: { 
 
\t \t \t \t \t    column: { 
 
\t \t \t \t \t     pointPadding: 0.2, 
 
\t \t \t \t \t     borderWidth: 0 
 
\t \t \t \t \t    } 
 
\t \t \t \t \t   }, 
 
\t \t \t \t \t   series:[data] 
 
\t \t \t \t \t  
 
\t \t \t \t \t \t 
 
\t \t \t \t \t }); 
 
}

[{"duration":120,"date":1418803200000},{"duration":90,"date":1418889600000},{"duration":90,"date":1418976000000},{"duration":90,"date":1419235200000},{"duration":20,"date":1419580800000},{"duration":80,"date":1419667200000},{"duration":120,"date":1419753600000},{"duration":90,"date":1419840000000},{"duration":90,"date":141992600000}] 
 

 

 
This is my JSON response

回答

0

的問題是,你必須在JSON自定義名稱。它應該是持久和日期字段的x/y。此行更多:series:[data]應替換爲series:data,因爲您的json是數組。

相關問題