【发布时间】:2015-01-20 15:52:03
【问题描述】:
我必须制作一个使用 Highcharts 动态更新数据的应用程序。这不是一个大问题,因为他们有一个很好的教程。该示例运行良好。
当我不想在多个设备上共享这个应用程序(使用 xampp)时,我遇到了一些问题。当我打开我的 web 应用程序的链接时:
http://IP-adress/ENRGYMONITOR/index.html
图表显示,但没有数据显示或更新。这是我写的javascript:
var chart; // global
/**
* Request data from the server, add it to the graph and set a timeout to request again
*/
function requestData() {
$.ajax({
url: 'http://localhost/live-server-data.php',
success: function(point) {
var series = chart.series[0],
shift = series.data.length > 20; // shift if the series is longer than 20
// add the point
chart.series[0].addPoint(eval(point), true, shift);
// call it again after one second
setTimeout(requestData, 5000);
},
cache: false
});
}
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
events: {
load: requestData
}
},
title: {
text: 'Live random data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
maxZoom: 20 * 1000
},
yAxis: {
minPadding: 0.2,
maxPadding: 0.2,
title: {
text: 'Value',
margin: 80
}
},
series: [{
name: 'Random data',
data: []
}]
});
});
谁能告诉我问题是什么?
【问题讨论】:
标签: javascript web highcharts xampp webserver