rre*_*rey 10 javascript global undefined series highcharts
我认为这是因为我的全局var chart在我的函数requestData被调用时尚未设置.
这是我的高级图表代码 $(document).ready(function()
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
marginRight: 130,
marginBottom: 25,
events: {
load: requestData()
}
},
title: {
text: 'Reporte PMU',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
maxZoom : 20 * 1000,
title: {
text: 'tiempo'
},
labels : { y : 0, rotation: -60 }
},
yAxis: {
title: {
text: 'Amount'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: [{
name: 'serieTension',
data: []
}]
});
});
Run Code Online (Sandbox Code Playgroud)
这是我的 requestData ()
$.ajax({
url: 'data2.php',
success: function(point) {
var series =chart.series[0],
shift = series.data.length > 20; //shift if the series is longer than 20
//add point
chart.series[0].addPoint(point, true, shift);
setTimeout(requestData, 1000);
},
cache : false
});
}
Run Code Online (Sandbox Code Playgroud)
只是放置
var chart;
Run Code Online (Sandbox Code Playgroud)
在所有函数之外,在文档就绪处理程序旁边,使其成为全局函数.
编辑:
另外,在加载调用中添加引用
load: function() {
chart = this; // `this` is the reference to the chart
requestData();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31877 次 |
| 最近记录: |