2015-11-08 69 views
0

我試圖從ajax調用中收到成功後更新圖表,但出現此錯誤:TypeError: undefined is not an object (evaluating 'chart.yAxis')。我很確定我正確調用更新方法。有任何想法嗎?圖表的範圍是否受到影響?它在我檢查時定義。Highcharts錯誤:TypeError:undefined不是一個對象(評估'chart.yAxis')

var chart = .... chart .... 
$('button#glucose_goals').click(function() { 
    $.ajax({ 
     url:'glucose/goals', 
     type: 'POST', 
     data: $('form#glucose_boundary_form').serialize(), 
     success: function(data) { 
      chart.yAxis[0].update({ plotBands: [] }); 
      chart.redraw(); 
     } 
    }); 
}); 
+0

你能告訴你如何創建圖表嗎?對我來說,'chart'變量似乎不存儲圖表對象,但可能是jQuery對象。試試:'chart.highcharts()。yAxis [0] .update({...});'。 –

回答

0

您修剪了幾行代碼。 here is a working fiddle

$('#update1').click(function() { 
    chart.yAxis[0].update({ 
plotBands: [{ 
      color: '#FCFFC5', 
      from: 144, 
      to: 176, 
      id: 'plotband-1' 
     }] 
    }); 

}); 
相關問題