Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.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图表不显示y的值_Javascript_Highcharts - Fatal编程技术网

Javascript Highcharts图表不显示y的值

Javascript Highcharts图表不显示y的值,javascript,highcharts,Javascript,Highcharts,图表不显示y的值,y只显示随机值。 警报功能会对正确的值y进行采样。原因是$TextBox18.val;返回一个字符串,y接受一个整数。请先解析y值,然后再将其交给y 这里的例子:这里是工作原理 HTML: JS: events: { load: function () { // set up the updating of the chart each second

图表不显示y的值,y只显示随机值。 警报功能会对正确的值y进行采样。

原因是$TextBox18.val;返回一个字符串,y接受一个整数。请先解析y值,然后再将其交给y

这里的例子:

这里是工作原理

HTML:

JS:

 events: {
                    load: function () {

                        // set up the updating of the chart each second
                        var series = this.series[0];
                        setInterval(function () {
                            var x = (new Date()).getTime(), 
                               // y = Math.random();
                                y = $("#TextBox18").val();

                            series.addPoint([x, y], true, true);
                            alert(y);
                        }, 1000);
                    }
                }
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
Enter value for y:<input type="text" value="5" id="y">
$(function () {
    $(document).ready(function() {
        Highcharts.setOptions({
            global: {
                useUTC: false
            }
        });

        var chart;
        $('#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 = parseFloat($('#y').val()); //This value needs to be parsed to either any integer or float value
                            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++) {
                        data.push({
                            x: time + i * 1000,
                            y: Math.random()
                        });
                    }
                    return data;
                })()
            }]
        });
    });

});