Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.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 为什么海图回归;类型错误:未定义的变量字节“;?_Javascript_Jquery_Highcharts - Fatal编程技术网

Javascript 为什么海图回归;类型错误:未定义的变量字节“;?

Javascript 为什么海图回归;类型错误:未定义的变量字节“;?,javascript,jquery,highcharts,Javascript,Jquery,Highcharts,我试图在high chart的帮助下绘制一个图,并且使用load event,我试图在每1秒之后向图中添加值 在这个图中,我还想将轴显示为Mb、Kb、Gb数据。因此,我编写了一个函数来返回字节值Mb、Kb、Gb(用于序列和工具提示) 这是我的代码: // highchart options : var series1, series2 ; var chart = { type: 'bar', events: {

我试图在high chart的帮助下绘制一个图,并且使用load event,我试图在每1秒之后向图中添加值

在这个图中,我还想将轴显示为Mb、Kb、Gb数据。因此,我编写了一个函数来返回字节值Mb、Kb、Gb(用于序列和工具提示)

这是我的代码:

// highchart options :
var series1, series2 ;

var chart = {
          type: 'bar',
              events: {
                    load: function () {
                        // set up the updating of the chart each second
                        series1 = this.series[0];
                        series2 = this.series[1];

                        setInterval(function () {

                            add_function();

                        }, 1000);//call function each 1 second
                    }
                }


};

var tooltip = { 
          enabled: true, 
          formatter: function() { return fbytes(this.y,2);} 
}; 

var plotOptions = { 
          bar: { 
          }, 
          series: { 
            dataLabels: { 
                enabled: true, 
                formatter: function() { return fbytes(this.y,2);}, 
                inside: true, 
                style: {fontWeight: 'number'} 
            },   
            pointPadding: 0, 
            pointWidth:38 
          }, 
          column : { 
             grouping: true 
          }     
};

series= [
            {
             name: 'old',
             color: '#f9a80e',
             data: [,]
            }, 
            {
                name: 'new',
                color: '#89897f',
                data: [,]
            }
];
加载事件函数为:

Array.max = function (array) { 
        return Math.max.apply(Math, array); 
}; 
Array.min = function (array) { 
        return Math.min.apply(Math, array); 
}; 

add_function()
{ 
    var arr[];
    //getting array values here 
    var min_value = Array.min(arr); 
    var max_value = Array.max(arr); 

    var chart2 = $('#container').highcharts();
    chart2.yAxis[0].update({max:max_value, min: 0}, true); 

    series1.setData([arr[0],arr[2]], true, true); 
    series2.setData([arr[1],arr[3]], true, true);
  }
以及转换函数:

function fbytes(bytes, precision) { 
    var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; 
    var posttxt = 0; 
    if (bytes == 0) return '0 Bytes'; 
    if (bytes < 1024) { 
            return Number(bytes) + " " + sizes[posttxt]; 
    } 
    while( bytes >= 1024 ) { 
            posttxt++; 
            bytes = bytes / 1024; 
    } 
    return Math.round(bytes.toPrecision(precision)) + " " + sizes[posttxt]; 
}
我得到了
这个.y=未定义的
。发生了什么事


密码有错吗?有什么建议吗?

我使用您的代码创建了演示,并稍微修改了add_函数()。你是说这样的事吗

function add_function(series1, series2) {
    var chart2 = $('#container').highcharts(),
      increment = 1024,
      min_value,
      max_value,
      newVal1 = [],
      newVal2 = [];

    if (!series1.data.length && !series2.data.length) {
        var arr = [512, 128, 1024, 0];

        min_value = Array.min(arr);
        max_value = Array.max(arr);

        newVal1 = [arr[0], arr[2]];
        newVal2 = [arr[1], arr[3]];
    } else {
        series1.yData.forEach(function(sEl, sInx) {
            newVal1.push(sEl + increment);
        });

        series2.yData.forEach(function(sEl, sInx) {
            newVal2.push(sEl + increment);
        });
        max_value = Array.max(newVal1.concat(newVal2));
    }

    chart2.yAxis[0].update({
        max: max_value,
        min: 0
    }, true);

    series1.setData(newVal1, true, true);
    series2.setData(newVal2, true, true);
}
例如:

我认为,您可以使用第一个值绘制图表,然后使用方法图更新它。系列[0]。设置数据(数据,真);我相信你可以找到很多关于你的问题的资源。和一个有用的链接。我怎么能在第一次画画?但我得到了“未定义”再次。在
formatter:function(){return fbytes(this.y,2);}的.y中,
series数据您得到“未定义”是什么意思?正如您在示例中所看到的,数据标签和工具提示内容按应有的方式显示。
function add_function(series1, series2) {
    var chart2 = $('#container').highcharts(),
      increment = 1024,
      min_value,
      max_value,
      newVal1 = [],
      newVal2 = [];

    if (!series1.data.length && !series2.data.length) {
        var arr = [512, 128, 1024, 0];

        min_value = Array.min(arr);
        max_value = Array.max(arr);

        newVal1 = [arr[0], arr[2]];
        newVal2 = [arr[1], arr[3]];
    } else {
        series1.yData.forEach(function(sEl, sInx) {
            newVal1.push(sEl + increment);
        });

        series2.yData.forEach(function(sEl, sInx) {
            newVal2.push(sEl + increment);
        });
        max_value = Array.max(newVal1.concat(newVal2));
    }

    chart2.yAxis[0].update({
        max: max_value,
        min: 0
    }, true);

    series1.setData(newVal1, true, true);
    series2.setData(newVal2, true, true);
}