2014-02-28 16 views
0

我試圖添加一個類別與自己的系列,當點擊一個按鈕。 查看代碼; http://jsfiddle.net/3e9PH/使用addPoint時沒有動畫()

我的問題;爲什麼新的系列不像最初的系列裝載時那樣?

這是我的代碼:

chart.xAxis[0].categories.push("My new category"); 
chart.series[0].addPoint(['My new category', 5],false); 
chart.series[1].addPoint(['My new category', 10],false); 

在此先感謝。

回答

0

初始動畫創建方式與其他方式不同。解決方案是設置默認值= 0,然後更新到所需的一個,請參閱:http://jsfiddle.net/3e9PH/1/

此外,使用setCategories而不是推送到數組值。

代碼:

$btn.click(function() { 

    var chart = $("#container").highcharts(); 
    categories.push("My new category"); 
    chart.xAxis[0].setCategories(categories, false); 
    chart.series[0].data[pointIndex].update(['My new category', Math.random() * 10], false); 
    chart.series[1].data[pointIndex].update(['My new category', Math.random() * 10], false); 
    chart.xAxis[0].setExtremes(0, pointIndex); 
    pointIndex = pointIndex == 9 ? 0 : pointIndex + 1; 
});