每次 ajax 重繪 時,下面從 Highchart 生成的樣條都會“重新繪制”。
我的問題是,有沒有一種方法可以“就地”更新樣條曲線,以便每次重繪 時都不會重新繪制樣條曲線?
我試過設定 animation: false 但是重繪一直在發生。先感謝您!
JS代碼:
$(document).ready(function(){
function my_chart(response) {
// $('#data-container').highcharts({
chart = Highcharts.chart('data-container', {
chart: { renderTo: 'data-container',
defaultSeriesType: 'spline'
// animation: false
},
title: {
text: 'Live Reddit Stream'
},
xAxis: {//{ type: 'datetime',
categories: response.halfhour
},
yAxis: {
minPadding: 0.2,
maxPadding: 0.2,
title: {text: 'Value',
margin: 80}
},
series: [{
name: 'reddit_stream',
data: response.count
}]
});
}
$(function fetchdata() {
$.ajax({
url: '/fetch_data',
type:'POST',
dataType: '',
success: function(output_string){
//call my_chart function
my_chart(output_string);
},
complete:function(output_string){
setTimeout(fetchdata,10000);
},
error: function (xhr, ajaxOptions, thrownError){
console.log(xhr.statusText);
console.log(thrownError);
}
});
});
});
uj5u.com熱心網友回復:
您需要在系列級別禁用影片:
Highcharts.chart('container', {
...,
series: [{
animation: false,
...
}]
});
現場演示: http : //jsfiddle.net/BlackLabel/gmbLh1v3/
但是最好是更新圖表而不是在每次請求后創建一個新圖表。示例:http : //jsfiddle.net/BlackLabel/nxmqwp4j/
API參考:
https://api.highcharts.com/highcharts/chart.animation
https://api.highcharts.com/highcharts/series.line.animation
https://api.highcharts.com/class-reference/Highcharts.Chart#update
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/351333.html
標籤:javascript 查询 高图
