Highcharts 动态更新饼图mysql
Highcharts Dynamic update pie Chart mysql
我有一个馅饼,我想从 mysql 添加每 3 秒的动态更新 data.php.I 需要在 .ready(function() 中添加事件?
任何帮助将不胜感激。
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
backgroundColor:'rgba(255, 255, 255, 0.0)'
},
title: {
text: 'Grafic'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
},},
credits: {
enabled: false
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage.toFixed(4) +' %';}}}},
series: [{
type: 'pie',
data: []}]}
$.getJSON("data.php", function(json) {
options.series[0].data = json;
chart = new Highcharts.Chart(options);
});
});
http://www.w3schools.com/js/js_timing.asp
您可能想要使用 "setinterval"。
您可能还需要设置一个递归回调,以便它每次都更新 highcharts。
如果您有任何问题,请告诉我。
2016 年 9 月 29 日更新
这是另一种方法,在 jQuery 中使用递归设置超时,以防有帮助。
(function($){
$(function(){ //document.ready
});
(function recurseEvent(element){
element.doStuff();
setTimeout(function(){
recurseEvent(element);
}, 2000);
})($('#myElement'));
})(jQuery);`
我有一个馅饼,我想从 mysql 添加每 3 秒的动态更新 data.php.I 需要在 .ready(function() 中添加事件? 任何帮助将不胜感激。
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
backgroundColor:'rgba(255, 255, 255, 0.0)'
},
title: {
text: 'Grafic'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
},},
credits: {
enabled: false
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage.toFixed(4) +' %';}}}},
series: [{
type: 'pie',
data: []}]}
$.getJSON("data.php", function(json) {
options.series[0].data = json;
chart = new Highcharts.Chart(options);
});
});
http://www.w3schools.com/js/js_timing.asp
您可能想要使用 "setinterval"。
您可能还需要设置一个递归回调,以便它每次都更新 highcharts。
如果您有任何问题,请告诉我。
2016 年 9 月 29 日更新
这是另一种方法,在 jQuery 中使用递归设置超时,以防有帮助。
(function($){
$(function(){ //document.ready
});
(function recurseEvent(element){
element.doStuff();
setTimeout(function(){
recurseEvent(element);
}, 2000);
})($('#myElement'));
})(jQuery);`