Laravel 4项目中的高点没有显示

Highcharts in Laravel 4 project are not displayed

本文关键字:高点没 显示 项目 Laravel      更新时间:2023-09-26

我是Laravel的新手,所以每当我试图在代码中添加js函数时,我仍然会遇到问题。我需要在我的laravel项目中添加一个图表。首先,我只是复制了highcharts.com上可用的一个图表的代码,并将其粘贴到主视图中,但没有显示任何内容。当我将相同的代码添加到一个普通的html文件中时,图形显示正常。

这是我的javascript代码

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript">
$(function () {
    $(document).ready(function () {
    Highcharts.setOptions({
        global: {
        useUTC: false
        }
    });
      $('#container').highcharts({
        chart: {
          type: 'spline',
          animation: Highcharts.svg, // don't animate in old IE
          marginRight: 10,
          events: {
            load: function () {
              // set up the updating of the chart each second
              var series = this.series[0];
              setInterval(function () {
                var x = (new Date()).getTime(), // current time
                    y = Math.random();
                series.addPoint([x, y], true, true);
              }, 1000);
            }
          }
        },
        title: {
          text: 'Live random data'
        },
        xAxis: {
          type: 'datetime',
          tickPixelInterval: 150
        },
        yAxis: {
          title: {
            text: 'Value'
          },
          plotLines: [{
            value: 0,
            width: 1,
            color: '#808080'
          }]
        },
        tooltip: {
          formatter: function () {
            return '<b>' + this.series.name + '</b><br/>' +
              Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
              Highcharts.numberFormat(this.y, 2);
          }
        },
        legend: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        series: [{
          name: 'Random data',
          data: (function () {
            // generate an array of random data
            var data = [],
                time = (new Date()).getTime(),
                i;
            for (i = -19; i <= 0; i += 1) {
                data.push({
                    x: time + i * 1000,
                    y: Math.random()
                });
            }
            return data;
          }())
        }]
        });
        });
    });
</script>

和html代码

<div id="container" style="width:100%; height:400px;"></div>

如何显示图表有什么建议吗?提前谢谢。

我认为问题出在创建图表时使用的语法上:$('#container').highcharts...

highcharts函数似乎不是用laravel定义的。

还有另一种方法可以尝试:

var chart = new Highcharts.Chart({ 
                              chart: { 
                                  renderTo: 'container', 
                                  ... 
                              },
                              ...
            });