Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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
Variables Highstock-Can';是否使用文件中的值更新,数据类型?_Variables_Types_Highstock_Updating - Fatal编程技术网

Variables Highstock-Can';是否使用文件中的值更新,数据类型?

Variables Highstock-Can';是否使用文件中的值更新,数据类型?,variables,types,highstock,updating,Variables,Types,Highstock,Updating,我对JS、JQuery和Highcharts还是相当陌生的 HighStock中的“动态更新”示例: chart: { events: { load: function() { var series = this.series[0]; var y = 1; setInterval(function() { var x = (new Date()).getTime();

我对JS、JQuery和Highcharts还是相当陌生的

HighStock中的“动态更新”示例:

chart: {
    events: {
        load: function() {
            var series = this.series[0];
            var y = 1;
            setInterval(function() {
                var x = (new Date()).getTime();
                $.get('get_most_recent_point_from_database.php',function(data){
                alert( data);
                var y = data;
                // y = 10;
                alert( y);
                series.addPoint([x, y], true, true);
                });
            }, 1000);
        }
    }
},
“从_database.php获取_most_recent_point_”生成一个整数

警报显示整数,但series.addPoint不会将整数添加到图表中。图表上一片空白

“y=10;”(在代码中注释掉)将用10更新图表

我通过“var y=1”将y设置为整数;我认为这可能会有所帮助

有什么想法吗?如果有帮助的话,我可以把它全部放在JSFIDLE中

修复======================

    setInterval(function() {

     var x = (new Date()).getTime(), y;

     $.get('get_most_recent_point_from_database.php',function(data){

     y = parseFloat(data).toFixed(1);

     series.addPoint([x, y], true, true);

    });

  }, 1000);

您的数据看起来如何?可能是字符串,所以请尝试通过parseFloat(data)(如果是单点)转换它,或者在php中使用json_encode()。(这取决于php文件的外观)

就是这样parseFloat(数据)做到了这一点。这是一个单点,只是一个数字。我想这是有道理的,它被解读为一个字符串。谢谢你,先生。