0

尝试使用 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 执行脚本打印出结果似乎也不会产生脚本的输出,只有一个空行......我做错了什么?

4

1 回答 1

0

事实证明这是一个愚蠢的错误,因为我是这方面的菜鸟。我必须在我的计算机上设置一个网络服务器(我使用LAMP)并将我的 php 文件放入 /var/www/ 目录。很高兴这data:<?php $data = array(2,3,1,4); echo json_encode($data); ?>可以正常工作。

于 2013-10-24T04:18:05.953 回答