Highcharts从php脚本/unixtime格式化json数据



我编写了一个php脚本,目标是使用$.getJSON((函数。#

live-temp-data.php创建了一个json文件,其中的数据如下:data

这就是结果:折线图

我做错了什么?下面的代码。

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Highcharts Example</title>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript"></script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<script>
$(function () {
var chart;
$(document).ready(function() {
$.getJSON("live-temp-data.php", function(json) {
Highcharts.chart('container', {
chart: {
type: 'spline'
},
title: {
text: 'steinhagen-wetter.de'
},
subtitle: {
text: '2020'
},
yAxis: {
title: {
text: 'Temperature(°C)'
}
},
time:{
timezone: 'Europe/ Berlin'
},
xAxis: {
type: "datetime",
dateTimeLabelFormats: {
hour: '%H:%M', 
},
},
series: [{
name: 'Outside Temp °C',
data:  json
}]
});
});
});
});
</script>
</head>
</html>

1(打开web控制台,您将看到以下消息:

https://www.highcharts.com/errors/25/

如果您浏览此页面,您将收到错误消息:

找不到Moment.js库

使用global.timezone选项需要Moment.js库加载。

因此,导入该库或删除此选项,该问题就应该得到解决。

2( 您的HTML文档无效,所有内容都在head部分中,您应该有一个包含图形容器的body部分。

3( 您的JSON无效:["[1584713222000, 6.5]","[1584713572000, 6.6]","[1584713989000, 6.7]", ...数据项周围不应该有引号。

最新更新