尝试使用 Highstock 图重新创建一个简单的 html 页面示例,但没有成功。似乎和我在网上找到的多个例子一样,但情节仍然是空的。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>This is title</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
marginRight: 130,
marginBottom: 25,
},
title: {
text: 'test plot'
},
xAxis: {
type: 'datetime',
categories: []
},
yAxis: {
text: 'value'
},
series: [{name:'myline',data:'<?php $data = array(2,3,1,4); echo json_encode($data) ?>'}]
}
chart = new Highcharts.Chart(options);
});
</script>
</head>
<body>
<div id="container" style="width: 100%; height: 400px; margin: 0 auto"></div>
</body>
</html>
如果我将series
线路更改为
series: [{name:'myline',data:[2,3,1,4]}]
有用。所以,问题一定出在这一行并且与 php 脚本有关。
但是,我无法使其与 php 一起使用。尝试使用格式正确的数字打印字符串json_encrode
以及其他一些内容,但似乎无法使其正常工作。在这种情况下,我看到的只是没有线条的图表。从 php 执行脚本打印出结果似乎也不会产生脚本的输出,只有一个空行......我做错了什么?