计算数据域

用户名

我正在读取文件列表,filestoplot.txt并将它们加载到数组(datasets[fileno])。这些二维数组的结构相似,我想计算(所有组合数组的)每一列的最大值和最小值,以便可以正确地建立全局d3轴。但是,我的代码(如下所示)无法正确返回gloablmaxgloablmin

var files=[];
var datasets=[],totalfiles;
var i,j,dset=1,olddset=0,maxscale=0;
var maxnecr=0;
var cols=8;
var maxvalues=[];
var globalmin=[];gloablmax=[];

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function loadfilenames(){

d3.csv("./filestoplot.txt", 
function(file){
    files = file.map(function(d) { for (key in d) { fn=d[key]; } return fn; })
    totalfiles=files.length;
    for (i=0;i<totalfiles;i++){ 
        datasets[i]=[]; 
        loaddataset(i);
        maxvalues[i]=[];
    }
    if (filesloaded==(totalfiles-1)) maxmin();
}
);
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function loaddataset(fileno){
d3.csv(files[fileno],function(a){
    console.log("loading file "+filesloaded);filesloaded++;
    datasets[fileno]=a.map(function(d1) {
    return [
    +d1["f1"] ,
    +d1["f2"] ,
    +d1["f3"] ,
    +d1["f4"] ,
    +d1["f5"] ,
    +d1["f6"] ,
    +d1["f3"]/(+d1["f3"] + +d1["f5"]),
    +d1["f7"]
    ];
}
);
}
);
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function maxmin(){
for (j=0; j <cols; j++) {
    globalmin[j]=Math.Min.apply(null,d3.extent(maxvalues,function(d){ return d[j][0]; }))
    gloablmax[j]=Math.Max.apply(null,d3.extent(maxvalues,function(d){ return d[j][1]; }))
    //d3.extent(maxvalues,function(d){ console.log(d[j]);});
}
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

</script>

<body style="max-width:90%" onload="loadfilenames();">
<script>

function changedataset(el){
    console.log(el.checked)
    maxmin();
}
</script>
</body>

在chrome控制台上,我可以看到maxvalues具有正确的数据,但是maxmin显示此错误:

“未捕获的TypeError:无法读取未定义的属性'apply'”

对于任何指示,我将感激不尽。谢谢。

亚当·斯通

Apply仅使用两次,

Math.Min.apply
Math.Max.apply

如果apply是“未定义的属性”,则表示Math.Min和/或Math.Max是未定义的。

它看起来像你刚才有资本问题,尝试Math.minMath.max(当然也有可能是其他的问题,但应该是类型错误的来源)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章