Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Highcharts实时数据更新不起作用_Javascript_Highcharts - Fatal编程技术网

Javascript Highcharts实时数据更新不起作用

Javascript Highcharts实时数据更新不起作用,javascript,highcharts,Javascript,Highcharts,我是js的新手,只是从官方网站复制,代码是: <html> <head> <title>Charts using Socket.io and Highcharts</title> <script src="https://code.highcharts.com/stock/highstock.js"></script> <script src="https://code.highcharts.com/stock/mo

我是js的新手,只是从官方网站复制,代码是:

<html>

<head>
<title>Charts using Socket.io and Highcharts</title>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js">    </script>
<script>
    $(function () {

        Highcharts.setOptions({
            global: {
                useUTC: false
            }
        });

        // Create the chart
        Highcharts.stockChart('container', {
            chart: {
                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.round(Math.random() * 100);
                            series.addPoint([x, y], true, true);
                        }, 1000);
                    }
                }
            },

            rangeSelector: {
                buttons: [{
                    count: 1,
                    type: 'minute',
                    text: '1M'
                }, {
                    count: 5,
                    type: 'minute',
                    text: '5M'
                }, {
                    type: 'all',
                    text: 'All'
                }],
                inputEnabled: false,
                selected: 0
            },

            title: {
                text: 'Live random data'
            },

            exporting: {
                enabled: false
            },

            series: [{
                name: 'Random data',
                data: (function () {
                    // generate an array of random data
                    var data = [],
                        time = (new Date()).getTime(),
                        i;

                    for (i = -999; i <= 0; i += 1) {
                        data.push([
                            time + i * 1000,
                            Math.round(Math.random() * 100)
                        ]);
                    }
                    return data;
                }())
            }]
        });

    });
    </script>
</head>

<body>
    <div id="container" style="height: 400px; min-width: 310px"></div>
</body>

</html>

使用Socket.io和Highcharts的图表
$(函数(){
Highcharts.setOptions({
全球:{
useUTC:false
}
});
//创建图表
Highcharts.stockChart(‘容器’{
图表:{
活动:{
加载:函数(){
//设置图表的每秒更新
var系列=本系列[0];
setInterval(函数(){
var x=(新日期()).getTime(),//当前时间
y=数学圆(数学随机()*100);
系列。添加点([x,y],真,真);
}, 1000);
}
}
},
范围选择器:{
按钮:[{
计数:1,
键入:“分钟”,
文字:“1M”
}, {
计数:5,
键入:“分钟”,
文字:“5M”
}, {
键入:“全部”,
文字:“全部”
}],
输入:错误,
已选:0
},
标题:{
文本:“实时随机数据”
},
出口:{
已启用:false
},
系列:[{
名称:'随机数据',
数据:(函数(){
//生成一个随机数据数组
var数据=[],
时间=(新日期()).getTime(),
我

对于(i=-999;i在当前脚本标记之前添加以下内容:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

选中此项:


注意:
$(function(){..}
是用于文档就绪事件的jQuery较短方法,因此首先需要包含jQuery。我认为
Highcharts
创建/更新应该在页面加载后调用,这就是为什么在去掉“页面加载”的
$(function(){..}
时它不起作用的原因函数。

您添加了jquery库吗?应该是:
在您当前的脚本标记之前添加此函数。
:)各位,感谢您的耐心等待新手!我已经解决了这个问题。