[英]I can't get the column max values from my csv file.(Javascript D3)
So I'm trying to make a scatter plot graph that takes input from 2 drop down menus.所以我正在尝试制作一个从 2 个下拉菜单中获取输入的散点图 plot 图表。 Once the choices are made, that'll choose 2 of the columns in the csv file.做出选择后,将选择 csv 文件中的 2 列。
However, the max values vary between the choices, so i need the program to change with the varying choices made by the user.但是,最大值因选择而异,因此我需要程序根据用户做出的不同选择进行更改。 So in the snippet of code which is going to be responsible for it, I feel that the syntax makes sense.所以在负责它的代码片段中,我觉得语法是有意义的。 The end result is that I tried storing the results in 2 separate variables and printing to the console, and the results come out as "undefined", but no errors.最终结果是我尝试将结果存储在 2 个单独的变量中并打印到控制台,结果显示为“未定义”,但没有错误。 So I'm not sure where the issue is coming from.所以我不确定问题出在哪里。 If i hard code the columns and axis for any singular choice, the points show up no problem.如果我对任何单一选择的列和轴进行硬编码,那么这些点就没有问题。 But because I've set it dynamically, there aren't any values being captured I guess.但是因为我是动态设置的,所以我猜没有任何值被捕获。 Any help is appreciated.任何帮助表示赞赏。
d3.csv("datafile.csv",function(data){
var xMx = d3.max(data,function(d) { return d.xvalue; } );
var yMx = d3.max(data,function(d) { return d.yvalue; } );
console.log(xMx);[enter image description here][1]
//x-axis
var x = d3.scaleLinear().domain([0,xMx])
The version is:4.13.0 I've tried including the csv file.版本是:4.13.0 我试过包括 csv 文件。 https://i.stack.imgur.com/kq8Aq.jpg https://i.stack.imgur.com/kq8Aq.jpg
d3.csv()
does not automatically convert strings to numbers. d3.csv()
不会自动将字符串转换为数字。 I would recommend reading in the data, using d3.csv()
's row
argument to properly handle the data, and only then finding the max using d3.max()
's accessor.我建议读取数据,使用d3.csv()
的row
参数正确处理数据,然后才使用d3.max()
的访问器找到最大值。
Since you're using D3 4, it'd be something like由于您使用的是 D3 4,因此它类似于
d3.csv("datafile.csv", r => {
// this function returns a new object for each row.
// the + is common shorthand for parseFloat()
return {
xvalue: +r.xvalue,
yvalue: +r.yvalue
};
}, data => {
let xMx = d3.max(data, d => d.xvalue);
let yMx = d3.max(data, d => d.yvalue);
console.log(xMx, yMx);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.