我試圖用新數據數組更新現有數據系列,並在完成時調用redraw
函數。雖然這很好,但我不太滿意,因爲我想要進行某種增長/縮小轉型。我看到一個example by Highcharts(擺弄現有的數據集,然後點擊按鈕「設置新數據到選定的系列」),但我不能複製這種行爲。Highcharts - 柱狀圖重繪動畫
這是我寫什麼代碼:
var series, newSeriesThreshold = this.chart.series.length * 2;
for (var i = 0; i < data.length; i += 2) {
series = {
name: this.data[i].title,
data: this.data[i].data,
color: this.data[i].color
};
if (i >= newSeriesThreshold) {
this.chart.addSeries(series, false);
} else {
var currentSeries = this.chart.series[i/2];
currentSeries.setData(series.data, false);
}
}
this.chart.redraw();
這些創建圖表時的選項:
var config = {
chart: {
renderTo: $(this.container).attr('id'),
type: this.settings.type,
animation: {
duration: 500,
easing: 'swing'
}
},
title: {
text: null
},
legend: {
enabled: this.settings.legend.show
},
tooltip: {
formatter: function() {
return this.x.toFixed(0) + ": <b>" + this.y.toString().toCurrency(0) + '</b>';
}
},
xAxis: {
title: {
text: this.settings.xaxis.title,
style: {
color: '#666'
}
}
},
yAxis: {
title: {
text: this.settings.yaxis.title,
style: {
color: '#666'
}
}
},
series: series,
plotOptions: {
column: {
color: '#FF7400'
}
},
credits: {
enabled: false
}
};
這就產生了一個即時更新沒有過渡效果。任何想法我可能做錯了什麼?
有什麼錯誤?你能記錄你的數據響應,看看它是否是預期值? –
沒有錯誤。圖表只是用新值更新而沒有任何轉換效果。通過源代碼,'doAnimation = animation && series.animate'產生'false',因爲'series.animate'爲null! – Leonard
我不需要重繪來查看更新的數據,但我也想知道爲什麼在柱形圖上沒有過渡效應。 – Ethereal