2013-02-28 133 views
1

我写了下面的代码:Highcharts addPoint:无法获得属性 'addPoint' 的值:对象为空或未定义

$(function instituciju_sprendimu_priemimo_palyginimas() { 
var chart;  
$(document).ready(function() {  
    // Build the chart 
    chart = new Highcharts.Chart({ 
     chart: { 
      renderTo: 'container6', 
      plotBackgroundColor: null, 
      plotBorderWidth: null, 
      plotShadow: false 
     }, 
     title: { 
      text: 'Institucijų sprendimų priemimo statistika' 
     }, 
     tooltip: { 
      pointFormat: '{series.name}: <b>{point.percentage}%</b>', 
      percentageDecimals: 1 
     }, 
     plotOptions: { 
      pie: { 
       allowPointSelect: true, 
       cursor: 'pointer', 
       dataLabels: { 
        enabled: false 
       }, 
       showInLegend: true 
      } 
     }, 
     series: [{ 
      type: 'pie', 
      name: ' ', 
      data: [] 
     }] 
    }); 
    chart.series[0].addPoint(['test1',100]);    
    chart.series[0].addPoint(['test2',200]); 
});  
}); 

我得到了以下错误:

addPoint: Unable to get value of the property 'addPoint': object is null or undefined.

我知道,我的问题可能很愚蠢,但我只是一个新手。

+0

重新创建你在[jsfiddle.net(http://jsfiddle.net/)图,并添加链接你的问题,那么你会得到答案更快。 – 2013-02-28 10:00:33

回答

2

看看例子:http://jsfiddle.net/WyDH8/哪个效果不错。另外我建议把addPoint函数放在回调函数Highcharts中,那么你将避免使用null对象。

http://jsfiddle.net/WyDH8/1/

chart = new Highcharts.Chart({ 
     //parameter... 
    },function(chart){ 

      chart.series[0].addPoint(['test1', 100]); 
      chart.series[0].addPoint(['test2', 200]); 

    }); 
+0

谢谢你,塞巴斯蒂安!有用! – 2013-02-28 11:57:24

相关问题